Пример #1
0
 def test_datapropertyassertion(self):
     x = Literal('"17"^^xsd:integer')
     y = DataPropertyAssertion(A.hasAge, A.Meg, x)
     self.assertEqual(
         'DataPropertyAssertion( a:hasAge a:Meg "17"^^xsd:integer )',
         DataPropertyAssertion(A.hasAge, A.Meg,
                               Literal('"17"^^xsd:integer')).to_functional(
                                   self.wa).getvalue())
Пример #2
0
 def test_literal(self):
     self.assertEqual('"testing"',
                      Literal("testing").to_functional(self.w).getvalue())
     self.w.reset()
     self.assertEqual(
         '"testing"',
         Literal("'testing'^^xsd:string").to_functional(self.w).getvalue())
     self.w.reset()
     self.assertEqual(
         '"AB\\"\\\\C\\""',
         Literal('AB\\"\\\\C\\"').to_functional(self.w).getvalue())
     self.w.reset()
     self.assertEqual(
         '"42"^^xsd:integer',
         Literal('"42"^^xsd:integer').to_functional(self.w).getvalue())
     with self.assertRaises(ValueError):
         Literal('"AB\\"\\\\C\\""^^xsd:integer')
     with self.assertRaises(ValueError):
         Literal('"ABC"^xsd:integer')
     with self.assertRaises(ValueError):
         Literal('"123"^^xsd.integer')
     self.assertTrue(isinstance('"42"^^xsd:integer', Literal))
     self.assertFalse(isinstance('"123"^^xsd.integer', Literal))
     self.w.reset()
     self.assertEqual(
         '"abc"@en-GB',
         Literal('"abc"@en-GB').to_functional(self.w).getvalue())
Пример #3
0
 def dataPropertyAssertion(
     self, expr: DataPropertyExpression.types(),
     sourceIndividual: Individual.types(), targetValue: Literal.types()
 ) -> "Ontology":
     self.axioms.append(
         DataPropertyAssertion(expr, sourceIndividual, targetValue))
     return self
Пример #4
0
 def test_bare_literal(self):
     for v, expected in various_literals:
         lv = Literal(v)
         self.w.reset()
         self.assertEqual(str(lv.to_functional(self.w)), expected)
Пример #5
0
 def test_datapropertyassertion_rdf(self):
     x = Literal('"17"^^xsd:integer')
     g = Graph()
     DataPropertyAssertion(A.hasAge, A.Meg, x).to_rdf(g)
     print('test_datapropertyassertion_rdf')
     print(g.serialize(format='turtle').decode())