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
    
    
# Get all classes

sc = b.getSubClasses('Thing', 0)

# set constraints

# Add nodes

statements = []
for c in sc:
    label = ''
    try:
        label = b.getLabel(c)
        label = re.sub("'", "\\'", label)
    except:
        pass
    is_obsolete = False
    try:
        if b.getAnnotation(c, 'deprecated') == 'true':
            is_obsolete = True
    except:
        pass
    statements.append('MERGE (c:Class { short_form : "%s")' % c)
    statements.append('MATCH (c:Class { short_form : "%s") SET c.label = "%s" SET c.is_obsolete = %r' 
                      % (c, label, is_obsolete))
        
nc.commit_list(statements)
b.sleep()
Beispiel #4
0
#!/usr/bin/env jython

from uk.ac.ebi.brain.core import Brain
import json

gorel = Brain()
gorel.learn("http://purl.obolibrary.org/obo/go/extensions/gorel.owl")

# Declaring AE rels as list for now.
relations = [ "GOREL_0001006" ]
# Would be better to pull list of AE rels automatically from file.
#With current structure, thus would require pulling subproperties.  Can't do that with Brain.

# Iterate over list, pulling usage and saving to file named for relation:

for r in relations:
    label = gorel.getLabel(r)
    usage = gorel.getAnnotation(r, "usage")
    usage_md = open("../.gitdown/" + label + "_usage.md", "w")
    usage_md.write(usage)
    usage_md.close()

gorel.sleep()


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