Esempio n. 1
0
    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
Esempio n. 2
0
 def writeTtl(self, path=None):
     g = OntGraph(path=path)
     self.populate(g)
     g.write(format='nifttl')
     return g