Exemple #1
0
 def test_negativedatapropertyassertion(self):
     TypedLiteral(5, XSD.integer)
     self.assertEqual(
         'NegativeDataPropertyAssertion( a:hasBrother a:Meg "5"^^xsd:integer )',
         NegativeDataPropertyAssertion(
             A.hasBrother, A.Meg,
             TypedLiteral(5,
                          XSD.integer)).to_functional(self.wa).getvalue())
Exemple #2
0
 def test_typed_literal(self):
     for v, expected in various_literals:
         lv = TypedLiteral(v)
         self.w.reset()
         self.assertEqual(expected, str(lv.to_functional(self.w)))
     # TODO: RDFLIB has some pretty strong literal typing -- if we try to use it out of the box, it tends to
     #       disappear things.
     rdflib.term.bind(A.bird, str)
     x = rdflib.Literal('Penguin', datatype=A.bird)
     self.assertEqual('"Penguin"^^<http://example.org/a#bird>',
                      str(TypedLiteral(x).to_functional(self.w.reset())))
Exemple #3
0
 def test_typedliteral(self):
     self.assertEqual(
         r'"\"AB\\\"\\\\C\\\"\""^^xsd:integer',
         TypedLiteral('"AB\\"\\\\C\\""',
                      XSD.integer).to_functional(self.w).getvalue())
     self.w.reset()
     self.assertEqual(
         r'"\"AB\\\"\\\\C\\\"\""^^<http://example.org/types/indigo>',
         TypedLiteral('"AB\\"\\\\C\\""',
                      "http://example.org/types/indigo").to_functional(
                          self.w).getvalue())
def lit_parser(value: str, rest: str) -> Tuple[rdflib.Literal, str]:
    if len(value) > 1 and value.startswith('"') and value.endswith('"'):
        value = value[1:-1]
    if rest.startswith('@'):
        m = literal_lang.match(rest)
        return rdflib.Literal(value, lang=m.group(1)), m_rem(m)
    elif rest.startswith('^^'):
        m = literal_datatype.match(rest)
        return TypedLiteral(value, m.group(1)), m_rem(m)
    else:
        return rdflib.Literal(value), rest
 def _eval_body(arg: Union[ARG_TYPE, List[ARG_TYPE]]) -> \
         Union[str, FunOwlBase, List[FunOwlBase]]:
     if isinstance(arg, str):
         return arg
     elif isinstance(arg, OWLFunc):
         return arg.decl
     elif isinstance(arg, rdflib.Literal):
         if arg.datatype:
             return TypedLiteral(arg.value, arg.datatype)
         elif arg.language:
             return StringLiteralWithLanguage(arg.value, arg.language)
         else:
             return FunOwlChoice(StringLiteralNoLanguage(arg))
     elif isinstance(arg, FunOwlBase):
         return arg
     else:
         return [OWLFunc._eval_body(b) for b in arg]
Exemple #6
0
    def test_negativedatapropertyassertion_rdf(self):
        g = Graph()
        NegativeDataPropertyAssertion(A.hasBrother, A.Meg, TypedLiteral(5, XSD.integer)).to_rdf(g)
        diff = compare_rdf("""@prefix ns1: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/a#Meg> a ns1:NamedIndividual .

<http://example.org/a#hasBrother> a ns1:DatatypeProperty .

[] a ns1:NegativePropertyAssertion ;
    ns1:assertionProperty <http://example.org/a#hasBrother> ;
    ns1:sourceIndividual <http://example.org/a#Meg> ;
    ns1:targetValue "5"^^xsd:integer .
""", g)
        if diff:
            print(diff)
            self.fail()
Exemple #7
0
 def test_literal_type(self):
     """ Subclasses of Literal are instances of literal """
     x = TypedLiteral(5, XSD.integer)
     self.assertEqual('5^^http://www.w3.org/2001/XMLSchema#integer', str(x))
     self.assertTrue(isinstance(TypedLiteral(5, XSD.integer), Literal))