C. Scott Ananian has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/389758 )

Change subject: Add new test case exercising conflicting types for a property
......................................................................

Add new test case exercising conflicting types for a property

In practice, Wikidata uses a blank node to represent "any value",
which can conflict with other assertions of typed values for the
same property.  This test case ensures that these conflicting types
won't cause problems.

This is tests-first case added for
I45294572607926b68c60c9c2c0f306b8c8d14bc3.

Change-Id: I70f19c2257944f51aaa6b8df8673f3cc5e0a77e7
---
A tests/data/TypeConflict.jsonld
A tests/data/TypeConflict.nt
A tests/data/TypeConflict.rdf
A tests/data/TypeConflict.ttl
M tests/phpunit/RdfWriterTestBase.php
5 files changed, 88 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/purtle refs/changes/58/389758/1

diff --git a/tests/data/TypeConflict.jsonld b/tests/data/TypeConflict.jsonld
new file mode 100644
index 0000000..bb0cc7d
--- /dev/null
+++ b/tests/data/TypeConflict.jsonld
@@ -0,0 +1,35 @@
+{
+    "@graph": [
+        {
+            "@id": "ex:A",
+            "ex:foo": [
+                {
+                    "@id": "ex:Node"
+                },
+                {
+                    "@type": "xsd:decimal",
+                    "@value": "5"
+                },
+                "string"
+            ],
+            "ex:bar": [
+                "string",
+                {
+                    "@type": "xsd:decimal",
+                    "@value": "5"
+                }
+            ],
+            "ex:bat": "string"
+        },
+        {
+            "@id": "ex:B",
+            "ex:bat": {
+                "@id": "_:genid1"
+            }
+        }
+    ],
+    "@context": {
+        "ex": "http://example.com/";,
+        "xsd": "http://www.w3.org/2001/XMLSchema#";
+    }
+}
\ No newline at end of file
diff --git a/tests/data/TypeConflict.nt b/tests/data/TypeConflict.nt
new file mode 100644
index 0000000..0596374
--- /dev/null
+++ b/tests/data/TypeConflict.nt
@@ -0,0 +1,7 @@
+<http://example.com/A> <http://example.com/foo> <http://example.com/Node> .
+<http://example.com/A> <http://example.com/foo> 
"5"^^<http://www.w3.org/2001/XMLSchema#decimal> .
+<http://example.com/A> <http://example.com/foo> "string" .
+<http://example.com/A> <http://example.com/bar> "string" .
+<http://example.com/A> <http://example.com/bar> 
"5"^^<http://www.w3.org/2001/XMLSchema#decimal> .
+<http://example.com/A> <http://example.com/bat> "string" .
+<http://example.com/B> <http://example.com/bat> _:genid1 .
diff --git a/tests/data/TypeConflict.rdf b/tests/data/TypeConflict.rdf
new file mode 100644
index 0000000..c502a13
--- /dev/null
+++ b/tests/data/TypeConflict.rdf
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"; xmlns:ex="http://example.com/";>
+       <rdf:Description rdf:about="http://example.com/A";>
+               <ex:foo rdf:resource="http://example.com/Node"/>
+               <ex:foo 
rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal";>5</ex:foo>
+               <ex:foo>string</ex:foo>
+               <ex:bar>string</ex:bar>
+               <ex:bar 
rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal";>5</ex:bar>
+               <ex:bat>string</ex:bat>
+       </rdf:Description>
+       <rdf:Description rdf:about="http://example.com/B";>
+               <ex:bat rdf:nodeID="genid1"/>
+       </rdf:Description>
+</rdf:RDF>
diff --git a/tests/data/TypeConflict.ttl b/tests/data/TypeConflict.ttl
new file mode 100644
index 0000000..ca0f99c
--- /dev/null
+++ b/tests/data/TypeConflict.ttl
@@ -0,0 +1,12 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix ex: <http://example.com/> .
+
+ex:A ex:foo ex:Node,
+               "5"^^xsd:decimal,
+               "string" ;
+       ex:bar "string",
+               "5"^^xsd:decimal ;
+       ex:bat "string" .
+
+ex:B ex:bat _:genid1 .
diff --git a/tests/phpunit/RdfWriterTestBase.php 
b/tests/phpunit/RdfWriterTestBase.php
index 7d686d5..6ea3145 100644
--- a/tests/phpunit/RdfWriterTestBase.php
+++ b/tests/phpunit/RdfWriterTestBase.php
@@ -372,6 +372,26 @@
                $this->assertOutputLines( 'AlternatingValues', $rdf );
        }
 
+       public function testTypeConflict() {
+               $writer = $this->newWriter();
+               $writer->prefix( 'ex', 'http://example.com/' );
+               $writer->start();
+               $writer->about( 'ex', 'A' )
+                       ->say( 'ex', 'foo' )->is( 'ex', 'Node' )
+                       ->say( 'ex', 'foo' )->value( '5', 'xsd', 'decimal' )
+                       ->say( 'ex', 'foo' )->value( 'string' )
+                       ->say( 'ex', 'bar' )->value( 'string' )
+                       ->say( 'ex', 'bar' )->value( '5', 'xsd', 'decimal' )
+                       ->say( 'ex', 'bat' )->value( 'string' );
+               // A blank node is used in clients to indicate "any value"
+               $writer->about( 'ex', 'B' )
+                       ->say( 'ex', 'bat' )->is( '_', $writer->blank() );
+
+               $writer->finish();
+               $rdf = $writer->drain();
+               $this->assertOutputLines( 'TypeConflict', $rdf );
+       }
+
        /**
         * @param string $datasetName
         * @param string[]|string $actual

-- 
To view, visit https://gerrit.wikimedia.org/r/389758
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I70f19c2257944f51aaa6b8df8673f3cc5e0a77e7
Gerrit-PatchSet: 1
Gerrit-Project: purtle
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian <canan...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to