Ejemplo n.º 1
0
 def get_json_doc(self, api, id):
     # construct url from id
     url = AVAILABLE_API_SOURCES[api]['annotate_syntax'].replace('*', id)
     json_doc = fetch_doc_from_api(url)
     context = load_context(api)
     json_doc.update(context)
     self.jsonld_doc = nquads_transform(json_doc)
     return json_doc
def compose_query_parameter_from_uri(uri, value, api):
    context = load_context(api)
    context.pop('root')
    query_string = ''
    if uri in get_uri_list(context):
        path_list = get_uri_list(context)[uri]
        for _item in path_list:
            query_string = query_string + ' ' + _item + ':' + value + ' OR'
    return query_string.strip(' OR')
Ejemplo n.º 3
0
def get_discrepancy_id(output_file_name, mongo_collection, uri):
	src = get_src_db()
	context = load_context('mygene.info')
	data = src[mongo_collection].find()
	with open(output_file_name, 'w') as f:
		for _doc in data:
			_doc.update(context)
			jsonld_doc = nquads_transform(_doc)
			rsid = fetch_value_by_uri(jsonld_doc, uri)
			if type(rsid) == list:
				f.write(_doc['_id'] + "\n")
Ejemplo n.º 4
0
def uri_to_field_name(uri, api, relation=None):
    context = load_context(api)
    if relation:
        return [
            _field for _field, _uri in context["@context"].items()
            if uri == _uri["@type"] and relation == _uri["@id"]
        ]
    else:
        return [
            _field for _field, _uri in context["@context"].items()
            if uri == _uri["@type"]
        ]
Ejemplo n.º 5
0
def relation_handler():
    add_nodes_edges = []
    relation_edge = 0
    edges= []
    for _id in AVAILABLE_IDS.keys():
        add_nodes_edges.append({'data': {'id': _id, 'type': 'id'}})
    for _api in AVAILABLE_API_SOURCES.keys():
        add_nodes_edges.append({'data': {'id': _api, 'type': 'api'}})
        if 'annotate_ids' in AVAILABLE_API_SOURCES[_api]:
            for annotate_id in AVAILABLE_API_SOURCES[_api]['annotate_ids']:
                add_nodes_edges.append({'data': {'id': relation_edge, 'source': annotate_id, 'target': _api, 'label': 'input'}})
                relation_edge += 1
        if 'jsonld' in AVAILABLE_API_SOURCES[_api]:
            context = load_context(_api)
            for k, v in context['@context'].items():
                _edge = {'data': {'source': find_id_from_uri(v["@type"]), 'target': _api, 'label': v["@id"]}}
                if _edge not in edges:
                    _edge['data']['id'] = relation_edge
                    add_nodes_edges.append(_edge)
                    edges.append(_edge)
                    relation_edge += 1
                else:
                    print(_edge)
    return add_nodes_edges
Ejemplo n.º 6
0
def uri_to_field_name(uri, api):
    context = load_context(api)
    return [
        _field for _field, _uri in context["@context"].items() if _uri == uri
    ]