def graph(self): if not hasattr(self, '_graph'): self._graph = populateFromJsonLd(OntGraph(), self.asJsonLd()) OntCuries.populate(self._graph) self.populateHeader(self._graph) return self._graph
def graph(self): g = OntGraph() OntCuries.populate(g) self.populate(g) g.bind('local', self.context) g.bind('apinatomy', readable) # FIXME populate from store g.bind('elements', elements) return g
def graphFromGithub(link, verbose=False): # mmmm no validation # also caching probably if verbose: log.info(link) g = OntGraph().parse(f'{link}?raw=true', format='turtle') OntCuries.populate(g) return g
def populate(self, graph=None): """ Populate a graph, or if no graph is provided populate a new empty graph from the current content. (Also useful for debug) """ if graph is None: graph = OntGraph() [graph.add(t) for t in self.triples] OntCuries.populate(graph) return graph
def import_tree(graph, ontologies, **kwargs): for ontology in ontologies: thisfile = Path(ontology).name print(thisfile) OntCuries.populate(graph) j = graph.asOboGraph('owl:imports', restriction=False) try: t, te = creatTree(*Query(f'NIFTTL:{thisfile}', 'owl:imports', 'OUTGOING', 30), json=j, prefixes=dict(graph.namespace_manager), **kwargs) #print(t) yield t, te except KeyError: print(tc.red('WARNING:'), 'could not find', ontology, 'in import chain') # TODO zap onts w/o imports
def new_index(self, referenceIndex, *, commit=True): """ reference hosts have a single incrementing primary key index to which everything is mapped in theory these indexes could also be per 'prefix' aka the sandboxed uri path or external uri path to which something is mapped I don't see any reason not to do this for this kind of implementation since a regular pattern can be develop """ ''' QUESTION: do we force a remapping of external id sequences into uris/ first? this seems like a bad idea? or rather, it is actually a good idea, but it will have to be done with a pattern based redirect instead of an actual materialization the alternative is to do what ontobee does and pass the external iri as a query parameter ... hrm tradoffs, well we certainly can't make a nice /uberon/uris/obo/{UBERON_} folder if we include the whole uri ... so this seems a reasonable tradeoff http://purl.obolibrary.org/obo/ can wind up being mapped into multiple uri spaces ... /obo/uris/obo/ would seem to make more sense but how to indicate that other organizations/projects map there ... /uberon/uris/obo/UBERON_ could indicate the latest sequence ah, and of course in theory this gets us out of the very annoying situation where /uberon/uris/obo/UBERON_ really IS different than /doid/uris/obo/UBERON_ for some identifiers (sigh) and if they are all mapped and masking based on presence then we can detect the issues HOWEVER how do we enforce that in reality the _mapping_ is all to /obo/uris/obo/ ?? ''' path = self.path_index(referenceIndex) rrp = path.repo_relative_path s = sncho[rrp.with_suffix('').as_posix()] # TODO check ownership if path.exists(): raise FileExistsError(path) g = OntGraph(path=path) OntCuries.populate(g) # TODO these are really identified by the follow: # base/readable/ # {group}/uris/ # base/ontologies/ # {group}/ontologies/uris/ pos = ( (rdf.type, snchn.IndexGraph), (rdfs.label, rdflib.Literal(f'IndexGraph for {referenceIndex}')), (snchn.referenceIndex, rdflib.Literal(referenceIndex)), # TODO HRM #(snchn.indexRemote, ) ) for po in pos: g.add((s, *po)) # FIXME g.path.parent.mkdir(parents=True) g.write() if commit: path.commit(f'add new index for {referenceIndex}') return path