Beispiel #1
0
class om():
    def __init__(self, uri_or_fp):
        self.b = Brain()
        self.b.learn(uri_or_fp)
        self.o = self.b.getOntology()
        self.bsfp = self.b.getBidiShortFormProvider(
        )  # uses .getEntity(<string> shortForm), .getShortForm(OWLEntity entity)

    def get_OP_list(self):
        s = self.o.getObjectPropertiesInSignature()
        out = []
        for r in s:
            out.append(self.bsfp.getShortForm(r))
        return out

    def roll_pdm(self, id_name):
        # TODO - get subsets + regular domain and range
        out = {}
        relations = self.get_OP_list()
        local_domains = []
        local_ranges = []
        for r in relations:
            #Assumes everything in file has a shorthand! # Better to key primary model on shortFormID and then re-key after reading.
            shorthand = self.b.getAnnotation(r, "shorthand")
            out[shorthand] = {}
            out[shorthand]['label'] = self.b.getLabel(r)
            try:
                out[shorthand]['usage'] = self.b.getAnnotation(r, "usage")
                out[shorthand]['defn'] = self.b.getAnnotation(r, "IAO_0000115")
                local_domains = self.b.getAnnotation(r,
                                                     "local_domain").split(" ")
                local_ranges = self.b.getAnnotation(r,
                                                    "local_range").split(" ")
            except:
                pass
            if local_domains:
                ldd = {}
                for ld in local_domains:
                    if ld in id_name.keys():
                        ldd[ld] = id_name[ld]
                    else:
                        ldd[ld] = ''
                out[shorthand]['local_domain'] = str(ldd)
            if local_ranges:
                lrd = {}
                for lr in local_ranges:
                    if lr in id_name.keys():
                        lrd[lr] = id_name[lr]
                    else:
                        lrd[lr] = ''
                out[shorthand]['local_range'] = str(lrd)
        return out
class om():
    
    def __init__(self, uri_or_fp):
       self.b = Brain()
       self.b.learn(uri_or_fp)
       self.o = self.b.getOntology()
       self.bsfp = self.b.getBidiShortFormProvider() # uses .getEntity(<string> shortForm), .getShortForm(OWLEntity entity)

    def get_OP_list(self):
        s = self.o.getObjectPropertiesInSignature()
        out = []
        for r in s:
            out.append(self.bsfp.getShortForm(r))
        return out
        
    def roll_pdm(self, id_name):
        # TODO - get subsets + regular domain and range
        out = {}
        relations = self.get_OP_list()
        local_domains = []
        local_ranges = []
        for r in relations:
            #Assumes everything in file has a shorthand! # Better to key primary model on shortFormID and then re-key after reading.
            shorthand = self.b.getAnnotation(r, "shorthand")
            out[shorthand] = {}
            out[shorthand]['label'] = self.b.getLabel(r)
            try:
                out[shorthand]['usage'] = self.b.getAnnotation(r, "usage")
                out[shorthand]['defn'] = self.b.getAnnotation(r, "IAO_0000115")
                local_domains = self.b.getAnnotation(r, "local_domain").split(" ")
                local_ranges = self.b.getAnnotation(r, "local_range").split(" ")
            except:
                pass
            if local_domains:
                ldd = {}
                for ld in local_domains:
                    if ld in id_name.keys():
                        ldd[ld] = id_name[ld]
                    else:
                        ldd[ld] = ''
                out[shorthand]['local_domain'] = str(ldd)
            if local_ranges:
                lrd = {}           
                for lr in local_ranges:
                    if lr in id_name.keys():
                        lrd[lr] = id_name[lr]
                    else:
                        lrd[lr] = ''
                out[shorthand]['local_range'] = str(lrd)
        return out
class om():
    def __init__(self, uri_or_fp):
        self.b = Brain()
        self.b.learn(uri_or_fp)
        self.o = self.b.getOntology()
        self.bsfp = self.b.getBidiShortFormProvider(
        )  # uses .getEntity(<string> shortForm), .getShortForm(OWLEntity entity)
        self.ogw = OWLGraphWrapper(self.o)
        self.start_auto_text = "---------------Text extracted from ontology: DO NOT EDIT---------------"
        self.end_auto_text = "---------------END AUTO GENERATED SECTION---------------"

    def get_valid_OP_list(self):
        """Returns a list of relations in the display_for_curators subset"""
        s = self.o.getObjectPropertiesInSignature()
        out = []
        for r in s:
            # Slightly dodgy hard-wiring of validity criterion
            if 'display_for_curators' in self.ogw.getSubsets(r):
                out.append(self.bsfp.getShortForm(r))
        return out

    def test_then_get_annotation(self, entity_sfid, AP):
        content = ''
        try:
            content = self.b.getAnnotation(entity_sfid, AP)
        except:
            warnings.warn("%s has no annotations with %s" % (entity_sfid, AP))
            pass
        return content

    def gen_includes_md(self, r, id_name):
        """Generate markdown for inclusion in wiki page
        r = relation_shortFormId
        id_name = and id_name dict lookup to use for domain and range
        """
        # Be carful
        auto_text = "%s\n" % self.start_auto_text
        auto_text += "\n## %s\n" % self.test_then_get_annotation(
            r, "shorthand")
        auto_text += "* OWL ID: %s\n" % r
        auto_text += "* label: %s\n" % self.test_then_get_annotation(
            r, 'label')
        auto_text += "* synonyms\n%s\n" % str(
            list(self.ogw.getOBOSynonymStrings(self.bsfp.getEntity(r),
                                               [])))  # could be prettified
        auto_text += "\n### Definition\n%s\n" % self.test_then_get_annotation(
            r, "IAO_0000115")
        auto_text += "\n### Usage\n%s\n" % self.test_then_get_annotation(
            r, "usage")  #
        auto_text += "\n### Comment\n%s\n" % self.test_then_get_annotation(
            r, "comment")  #
        auto_text += "\n### Subsets\n%s\n" % str(
            self.ogw.getSubsets(
                self.bsfp.getEntity(r)))  # Perhaps only display AE_
        # Finding child and parent relations would take a reasoner object call.  Better for annotators to reply on graph.
        # MIght be useful to give some record of how often used in ontology

        local_domain = self.test_then_get_annotation(r, "local_domain")
        local_range = self.test_then_get_annotation(r, "local_range")
        ldd = {}
        if local_domain:
            for ld in local_domain.split(" "):
                if ld in id_name.keys():
                    ldd[ld] = id_name[ld]
                else:
                    ldd[ld] = ''
                    id_name[ld] = ''
        auto_text += "\n##local domain\n%s\n" % str(ldd)
        lrd = {}
        if local_range:
            for lr in local_range.split(" "):
                if lr in id_name.keys():
                    lrd[lr] = id_name[lr]
                else:
                    lrd[lr] = ''
                    id_name[lr] = ''

        auto_text += "\n## local range\n%s\n" % str(lrd)
        auto_text += "\n%s\n" % self.end_auto_text
        return auto_text
from owl2pdm_tools import ont_manager
from uk.ac.ebi.brain.core import Brain
from neo4j_tools import neo4j_connect
import sys
import re

"""Add typing via anonymous class expressions from OWL file.
Requires uniqueness constraint on individual & class short_form_id."""

nc = neo4j_connect(base_uri = sys.argv[1], usr = sys.argv[2], pwd = sys.argv[3])

vfb = Brain()
vfb.learn(sys.argv[4]) # Make this non-local
vom = ont_manager(vfb.getOntology())


# vom.typeAxioms2pdm(sfid = 'VFB_00005000')
# example = [{'isAnonymous': False, 'objectId': u'FBbt_00100247'},
#            {'relId': u'BFO_0000050', 'isAnonymous': True, 'objectId': u'FBbt_00003624'},
#            {'relId': u'BFO_0000050', 'isAnonymous': True, 'objectId': u'FBbt_00007011'},
#            {'relId': u'RO_0002292', 'isAnonymous': True, 'objectId': u'FBtp0014830'}]

# Simple to use. Only issue is resolution of short_form_ids.  This can be done as long as these are stored as attributes on relations.  These should be added in the process of adding named relations.  Check proposed schema on ticket...



# Get all inds by query

inds = vfb.getInstances("Thing", 0) 

# Could grab from neo4J avoiding Brain