Пример #1
0
    def test_haskey(self):
        self.assertEqual(
            '''HasKey( <http://snomed.info/id/12345> (
    <http://snomed.info/id/23456>
    <http://snomed.info/id/23457>
) (
    <http://snomed.info/id/23458>
    <http://snomed.info/id/23459>
) )''',
            str(
                HasKey(SCT['12345'], ObjectPropertyExpression(SCT['23456']),
                       ObjectPropertyExpression(SCT['23457']),
                       DataPropertyExpression(SCT['23458']),
                       DataPropertyExpression(SCT['23459'])).to_functional(
                           self.sw.reset())))
Пример #2
0
    def test_haskey(self):
        self.assertEqual(
            '''HasKey( :12345 (
    :23456
    :23457
) (
    :23458
    :23459
) )''',
            str(
                HasKey(SCT['12345'], ObjectPropertyExpression(SCT['23456']),
                       ObjectPropertyExpression(SCT['23457']),
                       DataPropertyExpression(SCT['23458']),
                       DataPropertyExpression(SCT['23459'])).to_functional(
                           self.sw.reset())))
Пример #3
0
 def inverseFunctionalObjectProperty(
     self, ope: ObjectPropertyExpression.types()) -> "Ontology":
     opep = ObjectPropertyExpression(ope)
     self.axioms.append(InverseFunctionalObjectProperty(opep))
     return self
Пример #4
0
 def inverseObjectProperties(self, exp1: ObjectPropertyExpression.types(), exp2: ObjectPropertyExpression.types()) \
         -> "Ontology":
     exp1p = ObjectPropertyExpression(exp1)
     exp2p = ObjectPropertyExpression(exp2)
     self.axioms.append(InverseObjectProperties(exp1p, exp2p))
     return self
Пример #5
0
 def subObjectPropertyOf(self, sub: SubObjectPropertyExpression.types(), sup: ObjectPropertyExpression.types()) \
         -> "Ontology":
     subp = SubObjectPropertyExpression(sub)
     supp = ObjectPropertyExpression(sup)
     self.axioms.append(SubObjectPropertyOf(subp, supp))
     return self
Пример #6
0
def parse_args(s: str) -> List[Union[ARG_TYPE, List[ARG_TYPE]]]:
    """
    Parse an argument list to a function

    :param s: everything between the parenthesis
    :return: arguments split up into functions, urls, literals or lists thereof
    """
    rval = []
    unparsed = s
    while unparsed:
        unparsed = unparsed[skip_comments(unparsed, 0):]
        m = prefix_re.match(unparsed)
        if m:
            rval.append(m.group(1))
            rval.extend(parse_args(m.group(2)))
            unparsed = unparsed[m.span()[1]:]
            continue
        m = inner_function_re.match(unparsed)
        if m:
            body = bytes(m_rem(m), encoding='utf8')
            args, pos = nested(body, 0)
            unparsed = body[pos:].decode()
            rval.append(OWLFunc(m.group(1), parse_args(args.decode())))
            continue
        m = blank_node_label_re.match(unparsed)
        if m:
            rval.append(m.group(1))
            unparsed = unparsed[m.span()[1]:]
            continue
        uri, pos = uri_matcher(unparsed, 0)
        if uri:
            rval.append(uri)
            unparsed = unparsed[pos:]
            continue
        # The nasty little HasKey parenthesis bit
        unparsed = unparsed.strip()
        m = nested_re.match(unparsed)
        if m:
            body = bytes(m.group(1).strip(), encoding='utf8')
            args, pos = nested(body, 0)
            opes = parse_args(args.decode())
            unparsed = body[pos:].decode().strip()
            rval.extend([ObjectPropertyExpression(e) for e in opes])
            m = nested_re.match(unparsed)
            if not m:
                raise ValueError(
                    f"HasKey DataPropertyExpressions clause missing: {unparsed}"
                )
            body = bytes(m.group(1).strip(), encoding='utf8')
            args, pos = nested(body, 0)
            opes = parse_args(args.decode())
            unparsed = body[pos:].decode().strip()
            rval.extend([DataPropertyExpression(e) for e in opes])
            continue
        m = literal_re.match(unparsed)
        if m:
            lit, unparsed = lit_parser(m.group(1), m_rem(m))
            rval.append(lit)
            continue
        if unparsed:
            raise ValueError(f"Unrecognized content: {unparsed[:20]}")

    return rval
Пример #7
0
 def test_ObjectHasValue(self):
     t = ObjectHasValue(ObjectPropertyExpression(A.foo), Individual(A.bar))
     print(t.to_functional(self.w).getvalue())
     g = Graph()
     t.to_rdf(g)
     print(g.serialize(format="turtle").decode())