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())))
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())))
def dataPropertyAssertion( self, expr: DataPropertyExpression.types(), sourceIndividual: Individual.types(), targetValue: Literal.types() ) -> "Ontology": self.axioms.append( DataPropertyAssertion(expr, sourceIndividual, targetValue)) return self
def __init__(self, *dataPropertyExpressions: DataPropertyExpression, annotations: List[Annotation] = None) -> None: dpes = [DataPropertyExpression(dpe) for dpe in dataPropertyExpressions] self.dataPropertyExpressions = ListWrapper(dpes, DataPropertyExpression) self.annotations = annotations or [] super().__init__()
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