Skip to content

Commit 6d7f1dc

Browse files
committed
fix for #210
1 parent d58cf5e commit 6d7f1dc

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/main/java/n10s/rdf/export/LPGRDFToRDFProcesssor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public Stream<Statement> streamLocalImplicitOntology() {
9797

9898
private String buildURI(String baseVocabNS, String name) {
9999
//TODO: we know what kind of graph we have from the config (fix this)
100-
Pattern regex = Pattern.compile("^(\\w+)" + PREFIX_SEPARATOR + "(.*)$");
100+
Pattern regex = Pattern.compile("^([-\\w]+)" + PREFIX_SEPARATOR + "(.*)$");
101101
Matcher matcher = regex.matcher(name);
102102
if (matcher.matches()) {
103103
String prefix = matcher.group(1);
@@ -109,7 +109,7 @@ private String buildURI(String baseVocabNS, String name) {
109109
String localName = matcher.group(2);
110110
return uriNsPart + localName;
111111
} else if (name.startsWith("http")) {
112-
//TODO make this test better?
112+
//TODO make this test better? (is this for the 'KEEP' case?)
113113
return name;
114114
} else {
115115
return baseVocabNS + name;

src/test/java/n10s/endpoint/RDFEndpointTest.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,72 @@ public void testCypherReturnsList() throws Exception {
266266

267267
}
268268

269+
@Test
270+
public void testPrefixwithHyphen() throws Exception {
271+
// Given
272+
final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService();
273+
274+
//first import onto
275+
try (Transaction tx = graphDatabaseService.beginTx()) {
276+
tx.execute("CREATE CONSTRAINT n10s_unique_uri "
277+
+ "ON (r:Resource) ASSERT r.uri IS UNIQUE");
278+
tx.commit();
279+
}
280+
try (Transaction tx = graphDatabaseService.beginTx()) {
281+
tx.execute("CALL n10s.graphconfig.init()");
282+
tx.execute("CALL n10s.nsprefixes.add(\"my-prefix\", \"http://www.example.com/example#\")");
283+
284+
tx.commit();
285+
}
286+
287+
String xmlrdf = "<rdf:RDF xmlns=\"http://www.example.com/example#\"\n" +
288+
" xml:base=\"http://www.example.com/example\"\n" +
289+
" xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n" +
290+
" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" +
291+
" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"\n" +
292+
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\"\n" +
293+
" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n" +
294+
" xmlns:example=\"http://www.example.com/example#\">\n" +
295+
" <owl:Ontology rdf:about=\"http://www.example.com/example\"/>\n" +
296+
" \n" +
297+
" <owl:ObjectProperty rdf:about=\"http://www.example.com/example#requires\"/>\n" +
298+
"\n" +
299+
" <owl:Class rdf:about=\"http://www.example.com/example#Enitity1\"/>\n" +
300+
"\n" +
301+
" <owl:Class rdf:about=\"http://www.example.com/example#Entity2\"/>\n" +
302+
"\n" +
303+
" <owl:NamedIndividual rdf:about=\"http://www.example.com/example#Enitity1Individual\">\n" +
304+
" <rdf:type rdf:resource=\"http://www.example.com/example#Enitity1\"/>\n" +
305+
" <requiresProp>12345</requiresProp>" +
306+
" <requires rdf:resource=\"http://www.example.com/example#Entity2Individual\"/>\n" +
307+
" </owl:NamedIndividual>\n" +
308+
"\n" +
309+
" <owl:NamedIndividual rdf:about=\"http://www.example.com/example#Entity2Individual\">\n" +
310+
" <rdf:type rdf:resource=\"http://www.example.com/example#Entity2\"/>\n" +
311+
" </owl:NamedIndividual>\n" +
312+
"</rdf:RDF>";
313+
314+
try (Transaction tx = graphDatabaseService.beginTx()) {
315+
tx.execute("CALL n10s.rdf.import.inline('" + xmlrdf + "','RDF/XML')");
316+
tx.commit();
317+
}
318+
319+
Response response = HTTP.withHeaders("Accept", "text/plain").GET(
320+
HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() +
321+
"neo4j/describe/http%3A%2F%2Fwww.example.com%2Fexample%23Enitity1Individual?format=RDF/XML");
322+
323+
String expected =
324+
"<http://www.example.com/example#Enitity1Individual> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/example#Enitity1> .\n" +
325+
"<http://www.example.com/example#Enitity1Individual> <http://www.example.com/example#requires> <http://www.example.com/example#Entity2Individual> .\n" +
326+
"<http://www.example.com/example#Enitity1Individual> <http://www.example.com/example#requiresProp> \"12345\" ." +
327+
"<http://www.example.com/example#Enitity1Individual> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .";
328+
assertEquals(200, response.status());
329+
System.out.println(response.rawContent());
330+
assertTrue(ModelTestUtils
331+
.compareModels(expected, RDFFormat.TURTLE, response.rawContent(), RDFFormat.RDFXML));
332+
333+
}
334+
269335

270336
@Test
271337
public void testCypherOnMovieDBReturnsList() throws Exception {

0 commit comments

Comments
 (0)