Example #1
0
 def test_part_of(self):
     eeeee = self.OntTerm('UBERON:0008933',
                          label='primary somatosensory cortex')
     g = OntGraph()
     [g.add(t) for t in eeeee.triples_simple]
     g.debug()
     po = [t for t in eeeee.triples_simple if partOf in t]
     assert po, 'sadness'
Example #2
0
    def triples(self):
        crossref_doi_pred = rdflib.term.URIRef('http://prismstandard.org/namespaces/basic/2.1/doi')
        for blob in self.data['identifier_metadata']:
            id = blob['id']
            if not isinstance(id, idlib.Stream):
                id = idlib.Auto(id)

            if not hasattr(id, 'asUri'):
                breakpoint()

            s = id.asUri(rdflib.URIRef)
            if 'source' in blob:
                source = blob['source']  # FIXME we need to wrap this in our normalized representation
                if source == 'Crossref':  # FIXME CrossrefConvertor etc. OR put it in idlib as a an alternate ttl
                    pos = (
                        (rdf.type, owl.NamedIndividual),
                        (rdf.type, TEMP[blob['type']]),
                        (dc.publisher, blob['publisher']),
                        #(dc.type, blob['type']),  # FIXME semantify
                        (dc.title, blob['title']),
                        (dc.date, self.published_online(blob)),  # FIXME .... dangerzone
                    )
                    g = OntGraph()
                    doi = idlib.Doi(id) if not isinstance(id, idlib.Doi) else id  # FIXME idlib streams need to recognize their own type in __new__
                    data = doi.ttl()
                    if data is None:  # blackfynn has some bad settings on their doi records ...
                        return

                    try:
                        g.parse(data=data, format='ttl')  # FIXME network bad
                    except BaseException as e:
                        loge.exception(e)

                    _tr = [s for s, p, o in g if p == crossref_doi_pred]
                    if _tr:
                        _their_record_s = _tr[0]
                        yield s, owl.sameAs, _their_record_s
                        yield from g
                    else:
                        g.debug()
                        log.critical('No crossref doi section in graph!')
                else:
                    msg = f'dont know what to do with {source}'
                    log.error(msg)
                    #raise NotImplementedError(msg)
                    return
            else:
                msg = f'dont know what to do with {blob} for {id.identifier}'
                log.error(msg)
                #raise NotImplementedError(msg)
                return

            for p, oraw in pos:
                if oraw is not None:
                    o = rdflib.Literal(oraw) if not isinstance(oraw, rdflib.URIRef) else oraw
                    yield s, p, o
Example #3
0
def methods_mapping():
    from pyontutils.namespaces import TEMP, ilxtr, tech
    from nifstd_tools import methods as m
    import rdflib

    # TODO add this to ibnode tests
    _before = OntResGit(methods,
                        ref='8c30706cbc7ccc7443685a34dec026e8afbbedd1')
    after = OntResGit(
        methods,
        ref='860c88a574d17e0d427c1101fa1947b730b613a9')  # renaming commit
    before = OntResGit(after.path, ref=after.ref + '~1')
    assert before.graph.identity() == _before.graph.identity()

    bg = before.graph
    ag = after.graph
    _, local = next(ag[:ilxtr.indexNamespace:])
    local = rdflib.Namespace(str(local))
    T0 = TEMP['0']
    l0 = local['0']
    b = OntGraph().populate_from_triples(bg.subjectGraph(T0))
    a = OntGraph().populate_from_triples(ag.subjectGraph(l0))
    b.debug()
    a.debug()
    it = b.subjectIdentity(T0)
    il = a.subjectIdentity(l0)
    assert it == il
    assert it in (il, )
    assert il in (it, )  # (it,) ni il  # SIGH
    assert it in {il: None}
    assert il in {it: None}
    r = b.subjectsRenamed(a)
    renamed = before.graph.subjectsRenamed(after.graph)
    assert (len(renamed) - 1 == max([
        int(v.rsplit('/', 1)[-1]) for v in renamed.values()
        if v != ilxtr.Something
    ]))

    (OntGraph(
        namespace_manager=after.graph.namespace_manager).populate_from_triples(
            before.graph.subjectsRenamedTriples(after.graph)).debug())
    return renamed

    index_graph = OntGraph(path=olr / 'ttl/generated/index-methods.ttl')
    # FIXME either use or record for posterity the commits where these
    # transformations were run rather than pointing to the branch name
    with org.repo.getRef('methods'):
        input_graph = org.graph
        output_graph = input_graph.mapTempToIndex(index_graph, TEMP, m.local)
        a, r, c = output_graph.subjectsChanged(input_graph)
        index_graph.write()
Example #4
0
 def test_new_index(self):
     rp = temp_path / 'sneechenator'
     wrangler = snch.SneechWrangler(rp)
     path_index = wrangler.new_index('uri.interlex.org')
     assert path_index.exists(), 'wat'
     g = OntGraph(path=path_index).parse()
     try:
         next(g[:rdf.type:snch.snchn.IndexGraph])
     except StopIteration:
         assert False, g.debug()
Example #5
0
 def debug(self):
     g = OntGraph()
     self.populate(g)
     log.debug('printing graph')
     g.debug()