@@ -0,0 +1,2541 @@
+# Ignore in-table results of neighbor searches%0A# Exclude certain tables%0A# keyword_search and neighbor_search, but on mutiple contexts%0A%0Aimport networkx as nx%0Afrom api.apiutils import Relation%0A%0Afrom modelstore.elasticstore import StoreHandler, KWType%0Afrom knowledgerepr import fieldnetwork%0Afrom algebra import API%0A%0Apath_to_serialized_model = %22/Users/arcarter/code/datadiscovery/test/testmodel/%22%0Anetwork = fieldnetwork.deserialize_network(path_to_serialized_model)%0Astore_client = StoreHandler()%0A%0Aapi = API(network, store_client)%0A%0A%0A# short variables for Scope%0A# These are used in keyword searches%0A# To specify what parts of a file will be searched%0Asource = KWType.KW_TABLE  # table/file/source name%0Afield = KWType.KW_SCHEMA  # colum names/fields%0Acontent = KWType.KW_TEXT  # content of the columns%0A%0A# Short variables for Relation%0A# These represent edge types in the graph%0A# and are used for neighbor searches%0Aschema = Relation.SCHEMA  # similar schemas%0Aschema_sim = Relation.SCHEMA_SIM  # Similar Schema Names%0A# similar content values. i.e. matching substrings and numbers%0Acontent_sim = Relation.CONTENT_SIM%0Aentity_sim = Relation.ENTITY_SIM  # similar column names%0Apkfk = Relation.PKFK  # join candidates%0A%0A# Short variables for api%0A# These are algebraic functions that can be used to discover data%0Akeyword_search = api.keyword_search%0Aneighbor_search = api.neighbor_search%0Apaths = api.paths%0Atraverse = api.traverse%0Aintersection = api.intersection%0Aunion = api.union%0Adifference = api.difference%0A%0A%0Adef search(kws, contexts=%5Bsource, field, content%5D):%0A    if isinstance(contexts, KWType):%0A        contexts = %5Bcontexts%5D%0A    drs = None%0A    if isinstance(kws, str):%0A        kws = %5Bkws%5D%0A%0A    for kw in kws:%0A        for kwtype in contexts:%0A            new_drs = keyword_search(kw, kwtype, max_results=500)%0A            drs = union(drs, new_drs)%0A    return drs%0A%0A%0Adef neighbors(i_drs, relations=Relation, exclude_origin=True):%0A    o_drs = None%0A%0A    if relations is None:%0A        relations = %5Bpkfk, content_sim, schema_sim%5D%0A    if isinstance(relations, Relation):%0A        relations = %5Brelations%5D%0A%0A    for relation in relations:%0A        new_drs = neighbor_search(i_drs, relation)%0A        o_drs = union(o_drs, new_drs)%0A%0A    if exclude_origin:%0A        o_drs = difference(o_drs, i_drs)%0A%0A    return o_drs%0A%0A%0Adef paths_between(a, b, primitive):%0A    pass%0A%0A%0Adef provenance(i_drs):%0A    return i_drs.get_provenance().prov_graph().edges()%0A%0A%0Adef make_drs(general_input):%0A    o_drs = api._general_to_drs(general_input)%0A    return o_drs%0A%0A%0Aif __name__ == '__sugar__':%0A    pass%0A

add sugar layer for demo