Skip to content

Commit

Permalink
added way to set api_key via SCICRUNCH_API_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
tgbugs committed Mar 22, 2018
1 parent 97909d7 commit db8cad7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ontquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,17 @@ def query(self, iri=None, label=None): # right now we only support exact matche
class SciGraphRemote(OntService): # incomplete and not configureable yet
cache = True
verbose = False
def __init__(self, api_key=None):
self.api_key = api_key
super().__init__()

def add(self, iri): # TODO implement with setter/appender?
raise TypeError('Cannot add ontology to remote service.')

def setup(self):
self.sgv = scigraph_client.Vocabulary(cache=self.cache, verbose=self.verbose)
self.sgg = scigraph_client.Graph(cache=self.cache, verbose=self.verbose)
self.sgc = scigraph_client.Cypher(cache=self.cache, verbose=self.verbose)
self.sgv = scigraph_client.Vocabulary(cache=self.cache, verbose=self.verbose, key=self.api_key)
self.sgg = scigraph_client.Graph(cache=self.cache, verbose=self.verbose, key=self.api_key)
self.sgc = scigraph_client.Cypher(cache=self.cache, verbose=self.verbose, key=self.api_key)
self.curies = self.sgc.getCuries() # TODO can be used to provide curies...
self.categories = self.sgv.getCategories()
self._onts = self.sgg.getEdges('owl:Ontology') # TODO incomplete and not sure if this works...
Expand Down Expand Up @@ -545,11 +549,13 @@ def query(self, *args, **kwargs): # needs to conform to the OntQuery __call__ s


def main():
import os
from IPython import embed
from pyontutils.core import PREFIXES as uPREFIXES
curies = OntCuries(uPREFIXES)
#print(curies)
query = OntQuery(SciGraphRemote())
api_key = os.environ['SCICRUNCH_API_KEY']
query = OntQuery(SciGraphRemote(api_key=api_key))
OntTerm.query = query

# direct use of query instead of via OntTerm, users should never have to do this
Expand Down

0 comments on commit db8cad7

Please sign in to comment.