rdftemplate

Library for generating XML documents from RDF data using templates
git clone https://code.djc.id.au/git/rdftemplate/
commit c87b9151425cf3d71d573c784184422c23981666
parent 40152613d397638b595eb43cb41aac14ac088000
Author: Dan Callaghan <djc@djc.id.au>
Date:   Sun, 15 Nov 2009 16:48:05 +1000

allow namespace prefix mappings to be customised in rdftemplate

Diffstat:
Msrc/main/antlr3/au/com/miskinhill/rdftemplate/selector/Selector.g | 17+++++++++++++++--
Dsrc/main/java/au/com/miskinhill/rdftemplate/NamespacePrefixMapper.java | 41-----------------------------------------
Msrc/main/java/au/com/miskinhill/rdftemplate/selector/AntlrSelectorFactory.java | 22+++++++++++-----------
Msrc/main/java/au/com/miskinhill/rdftemplate/selector/Traversal.java | 18+++++++-----------
Msrc/main/java/au/com/miskinhill/rdftemplate/selector/TypePredicate.java | 17+++++++----------
Msrc/test/java/au/com/miskinhill/rdftemplate/TemplateInterpolatorUnitTest.java | 4+++-
Asrc/test/java/au/com/miskinhill/rdftemplate/TestNamespacePrefixMap.java | 31+++++++++++++++++++++++++++++++
Msrc/test/java/au/com/miskinhill/rdftemplate/selector/EternallyCachingSelectorFactoryUnitTest.java | 6+++++-
Msrc/test/java/au/com/miskinhill/rdftemplate/selector/PredicateMatcher.java | 4++--
Msrc/test/java/au/com/miskinhill/rdftemplate/selector/SelectorEvaluationUnitTest.java | 4+++-
Msrc/test/java/au/com/miskinhill/rdftemplate/selector/SelectorParserUnitTest.java | 74++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/test/java/au/com/miskinhill/rdftemplate/selector/TraversalMatcher.java | 4++--
Msrc/test/resources/au/com/miskinhill/rdftemplate/test-data.xml | 2+-
13 files changed, 127 insertions(+), 117 deletions(-)
diff --git a/src/main/antlr3/au/com/miskinhill/rdftemplate/selector/Selector.g b/src/main/antlr3/au/com/miskinhill/rdftemplate/selector/Selector.g
@@ -2,6 +2,7 @@ grammar Selector;
 
 @parser::header {
 package au.com.miskinhill.rdftemplate.selector;
+import java.util.Map;
 }
 
 @parser::members {
@@ -13,6 +14,7 @@ package au.com.miskinhill.rdftemplate.selector;
     
     private AdaptationResolver adaptationResolver;
     private PredicateResolver predicateResolver;
+    private Map<String, String> namespacePrefixMap;
     
     public void setAdaptationResolver(AdaptationResolver adaptationResolver) {
         this.adaptationResolver = adaptationResolver;
@@ -22,6 +24,17 @@ package au.com.miskinhill.rdftemplate.selector;
         this.predicateResolver = predicateResolver;
     }
     
+    public void setNamespacePrefixMap(Map<String, String> map) {
+        this.namespacePrefixMap = map;
+    }
+    
+    private String ns(String prefix) {
+        String ns = namespacePrefixMap.get(prefix);
+        if (ns == null)
+            throw new InvalidSelectorSyntaxException("Unbound namespace prefix " + prefix);
+        return ns;
+    }
+    
 }
 
 @lexer::header {
@@ -119,7 +132,7 @@ traversal returns [Traversal result]
     : ( '!' { $result.setInverse(true); }
       | // optional
       )
-      nsprefix=XMLTOKEN { $result.setPropertyNamespacePrefix($nsprefix.text); }
+      nsprefix=XMLTOKEN { $result.setPropertyNamespace(ns($nsprefix.text)); }
       ':'
       localname=XMLTOKEN { $result.setPropertyLocalName($localname.text); }
       ( '['
@@ -186,7 +199,7 @@ predicate returns [Predicate result]
         localname=XMLTOKEN
         {
             try {
-                result = predicateClass.getConstructor(String.class, String.class).newInstance($nsprefix.text, $localname.text);
+                result = predicateClass.getConstructor(String.class, String.class).newInstance(ns($nsprefix.text), $localname.text);
             } catch (Exception e) {
                 throw new InvalidSelectorSyntaxException(e);
             }
diff --git a/src/main/java/au/com/miskinhill/rdftemplate/NamespacePrefixMapper.java b/src/main/java/au/com/miskinhill/rdftemplate/NamespacePrefixMapper.java
@@ -1,41 +0,0 @@
-package au.com.miskinhill.rdftemplate;
-
-import java.util.HashMap;
-
-import com.hp.hpl.jena.sparql.vocabulary.FOAF;
-import com.hp.hpl.jena.vocabulary.DCTerms;
-import com.hp.hpl.jena.vocabulary.DC_11;
-import com.hp.hpl.jena.vocabulary.OWL;
-import com.hp.hpl.jena.vocabulary.RDF;
-import com.hp.hpl.jena.vocabulary.RDFS;
-import com.hp.hpl.jena.vocabulary.XSD;
-
-public final class NamespacePrefixMapper extends HashMap<String, String> {
-    
-    private static final long serialVersionUID = 2119318190108418682L;
-    
-    private static final NamespacePrefixMapper instance = new NamespacePrefixMapper();
-    public static NamespacePrefixMapper getInstance() {
-        return instance;
-    }
-    
-    private NamespacePrefixMapper() {
-        put("mhs", "http://miskinhill.com.au/rdfschema/1.0/");
-        put("dc", DCTerms.NS);
-        put("old-dc", DC_11.NS);
-        put("foaf", FOAF.NS);
-        put("rdf", RDF.getURI());
-        put("rdfs", RDFS.getURI());
-        put("xs", XSD.getURI());
-        put("xsd", "http://www.w3.org/TR/xmlschema-2/#");
-        put("contact", "http://www.w3.org/2000/10/swap/pim/contact#");
-        put("geonames", "http://www.geonames.org/ontology#");
-        put("sioc", "http://rdfs.org/sioc/ns#");
-        put("awol", "http://bblfish.net/work/atom-owl/2006-06-06/#");
-        put("lingvoj", "http://www.lingvoj.org/ontology#");
-        put("prism", "http://prismstandard.org/namespaces/1.2/basic/");
-        put("owl", OWL.NS);
-        put("rev", "http://purl.org/stuff/rev#");
-    }
-    
-}
diff --git a/src/main/java/au/com/miskinhill/rdftemplate/selector/AntlrSelectorFactory.java b/src/main/java/au/com/miskinhill/rdftemplate/selector/AntlrSelectorFactory.java
@@ -1,5 +1,8 @@
 package au.com.miskinhill.rdftemplate.selector;
 
+import java.util.Collections;
+import java.util.Map;
+
 import org.antlr.runtime.ANTLRStringStream;
 import org.antlr.runtime.CharStream;
 import org.antlr.runtime.CommonTokenStream;
@@ -7,27 +10,23 @@ import org.antlr.runtime.RecognitionException;
 
 public class AntlrSelectorFactory implements SelectorFactory {
     
-    private final AdaptationResolver adaptationResolver;
-    private final PredicateResolver predicateResolver;
+    private AdaptationResolver adaptationResolver = new DefaultAdaptationResolver();
+    private PredicateResolver predicateResolver = new DefaultPredicateResolver();
+    private Map<String, String> namespacePrefixMap = Collections.emptyMap();
     
     public AntlrSelectorFactory() {
-        this.adaptationResolver = new DefaultAdaptationResolver();
-        this.predicateResolver = new DefaultPredicateResolver();
     }
     
-    public AntlrSelectorFactory(AdaptationResolver adaptationResolver) {
+    public void setAdaptationResolver(AdaptationResolver adaptationResolver) {
         this.adaptationResolver = adaptationResolver;
-        this.predicateResolver = new DefaultPredicateResolver();
     }
     
-    public AntlrSelectorFactory(PredicateResolver predicateResolver) {
-        this.adaptationResolver = new DefaultAdaptationResolver();
+    public void setPredicateResolver(PredicateResolver predicateResolver) {
         this.predicateResolver = predicateResolver;
     }
     
-    public AntlrSelectorFactory(AdaptationResolver adaptationResolver, PredicateResolver predicateResolver) {
-        this.adaptationResolver = adaptationResolver;
-        this.predicateResolver = predicateResolver;
+    public void setNamespacePrefixMap(Map<String, String> namespacePrefixMap) {
+        this.namespacePrefixMap = namespacePrefixMap;
     }
     
     @Override
@@ -38,6 +37,7 @@ public class AntlrSelectorFactory implements SelectorFactory {
         SelectorParser parser = new SelectorParser(tokens);
         parser.setAdaptationResolver(adaptationResolver);
         parser.setPredicateResolver(predicateResolver);
+        parser.setNamespacePrefixMap(namespacePrefixMap);
         try {
             return parser.unionSelector();
         } catch (RecognitionException e) {
diff --git a/src/main/java/au/com/miskinhill/rdftemplate/selector/Traversal.java b/src/main/java/au/com/miskinhill/rdftemplate/selector/Traversal.java
@@ -14,11 +14,9 @@ import com.hp.hpl.jena.rdf.model.Resource;
 import com.hp.hpl.jena.rdf.model.StmtIterator;
 import org.apache.commons.lang.builder.ToStringBuilder;
 
-import au.com.miskinhill.rdftemplate.NamespacePrefixMapper;
-
 public class Traversal {
     
-    private String propertyNamespacePrefix;
+    private String propertyNamespace;
     private String propertyLocalName;
     private boolean inverse = false;
     private Predicate predicate;
@@ -42,9 +40,7 @@ public class Traversal {
             throw new SelectorEvaluationException("Attempted to traverse non-resource node " + node);
         }
         Resource resource = (Resource) node;
-        Property property = resource.getModel().createProperty(
-                NamespacePrefixMapper.getInstance().get(propertyNamespacePrefix),
-                propertyLocalName);
+        Property property = resource.getModel().createProperty(propertyNamespace, propertyLocalName);
         List<RDFNode> destinations = new ArrayList<RDFNode>();
         if (!inverse) {
             for (StmtIterator it = resource.listProperties(property); it.hasNext(); ) {
@@ -70,7 +66,7 @@ public class Traversal {
     @Override
     public String toString() {
         return new ToStringBuilder(this)
-                .append("propertyNamespacePrefix", propertyNamespacePrefix)
+                .append("propertyNamespace", propertyNamespace)
                 .append("propertyLocalName", propertyLocalName)
                 .append("inverse", inverse)
                 .append("predicate", predicate)
@@ -87,12 +83,12 @@ public class Traversal {
         this.propertyLocalName = propertyLocalName;
     }
     
-    public String getPropertyNamespacePrefix() {
-        return propertyNamespacePrefix;
+    public String getPropertyNamespace() {
+        return propertyNamespace;
     }
     
-    public void setPropertyNamespacePrefix(String propertyNamespacePrefix) {
-        this.propertyNamespacePrefix = propertyNamespacePrefix;
+    public void setPropertyNamespace(String propertyNamespace) {
+        this.propertyNamespace = propertyNamespace;
     }
     
     public boolean isInverse() {
diff --git a/src/main/java/au/com/miskinhill/rdftemplate/selector/TypePredicate.java b/src/main/java/au/com/miskinhill/rdftemplate/selector/TypePredicate.java
@@ -8,20 +8,18 @@ import com.hp.hpl.jena.rdf.model.Statement;
 import com.hp.hpl.jena.vocabulary.RDF;
 import org.apache.commons.lang.builder.ToStringBuilder;
 
-import au.com.miskinhill.rdftemplate.NamespacePrefixMapper;
-
 public class TypePredicate implements Predicate {
     
-    private final String namespacePrefix;
+    private final String namespace;
     private final String localName;
     
-    public TypePredicate(String namespacePrefix, String localName) {
-        this.namespacePrefix = namespacePrefix;
+    public TypePredicate(String namespace, String localName) {
+        this.namespace = namespace;
         this.localName = localName;
     }
     
-    public String getNamespacePrefix() {
-        return namespacePrefix;
+    public String getNamespace() {
+        return namespace;
     }
     
     public String getLocalName() {
@@ -35,8 +33,7 @@ public class TypePredicate implements Predicate {
             throw new SelectorEvaluationException("Attempted to apply [type] to non-resource node " + node);
         }
         Resource resource = (Resource) node;
-        Resource type = resource.getModel().createResource(
-                NamespacePrefixMapper.getInstance().get(namespacePrefix) + localName);
+        Resource type = resource.getModel().createResource(namespace + localName);
         for (Statement statement: (Set<Statement>) resource.listProperties(RDF.type).toSet()) {
             if (statement.getObject().equals(type))
                 return true;
@@ -46,7 +43,7 @@ public class TypePredicate implements Predicate {
     
     @Override
     public String toString() {
-        return new ToStringBuilder(this).append(namespacePrefix).append(localName).toString();
+        return new ToStringBuilder(this).append(namespace).append(localName).toString();
     }
 
 }
diff --git a/src/test/java/au/com/miskinhill/rdftemplate/TemplateInterpolatorUnitTest.java b/src/test/java/au/com/miskinhill/rdftemplate/TemplateInterpolatorUnitTest.java
@@ -33,7 +33,9 @@ public class TemplateInterpolatorUnitTest {
         InputStream stream = this.getClass().getResourceAsStream(
                 "/au/com/miskinhill/rdftemplate/test-data.xml");
         model.read(stream, "");
-        templateInterpolator = new TemplateInterpolator(new AntlrSelectorFactory());
+        AntlrSelectorFactory selectorFactory = new AntlrSelectorFactory();
+        selectorFactory.setNamespacePrefixMap(TestNamespacePrefixMap.getInstance());
+        templateInterpolator = new TemplateInterpolator(selectorFactory);
     }
     
     @Test
diff --git a/src/test/java/au/com/miskinhill/rdftemplate/TestNamespacePrefixMap.java b/src/test/java/au/com/miskinhill/rdftemplate/TestNamespacePrefixMap.java
@@ -0,0 +1,31 @@
+package au.com.miskinhill.rdftemplate;
+
+import java.util.HashMap;
+
+import com.hp.hpl.jena.sparql.vocabulary.FOAF;
+import com.hp.hpl.jena.vocabulary.DCTerms;
+import com.hp.hpl.jena.vocabulary.RDF;
+import org.junit.Ignore;
+
+@Ignore // why does JUnit think this is a test?
+public final class TestNamespacePrefixMap extends HashMap<String, String> {
+    
+    public static final String MHS_NS = "http://miskinhill.com.au/rdfschema/1.0/";
+    
+    private static final long serialVersionUID = 2119318190108418683L;
+    
+    private static final TestNamespacePrefixMap instance = new TestNamespacePrefixMap();
+    public static TestNamespacePrefixMap getInstance() {
+        return instance;
+    }
+    
+    private TestNamespacePrefixMap() {
+        put("mhs", MHS_NS);
+        put("dc", DCTerms.NS);
+        put("foaf", FOAF.NS);
+        put("rdf", RDF.getURI());
+        put("sioc", "http://rdfs.org/sioc/ns#");
+        put("lingvoj", "http://www.lingvoj.org/ontology#");
+    }
+    
+}
diff --git a/src/test/java/au/com/miskinhill/rdftemplate/selector/EternallyCachingSelectorFactoryUnitTest.java b/src/test/java/au/com/miskinhill/rdftemplate/selector/EternallyCachingSelectorFactoryUnitTest.java
@@ -5,11 +5,15 @@ import static org.junit.Assert.assertThat;
 
 import org.junit.Test;
 
+import au.com.miskinhill.rdftemplate.TestNamespacePrefixMap;
+
 public class EternallyCachingSelectorFactoryUnitTest {
     
     @Test
     public void shouldCacheSelectors() {
-        EternallyCachingSelectorFactory factory = new EternallyCachingSelectorFactory(new AntlrSelectorFactory());
+        AntlrSelectorFactory wrappedFactory = new AntlrSelectorFactory();
+        wrappedFactory.setNamespacePrefixMap(TestNamespacePrefixMap.getInstance());
+        EternallyCachingSelectorFactory factory = new EternallyCachingSelectorFactory(wrappedFactory);
         Selector<?> first = factory.get("dc:creator/foaf:name");
         Selector<?> second = factory.get("dc:creator/foaf:name");
         assertThat((Selector) first, sameInstance((Selector) second));
diff --git a/src/test/java/au/com/miskinhill/rdftemplate/selector/PredicateMatcher.java b/src/test/java/au/com/miskinhill/rdftemplate/selector/PredicateMatcher.java
@@ -16,9 +16,9 @@ public class PredicateMatcher<T extends Predicate> extends BeanPropertyMatcher<T
         return m;
     }
     
-    public static PredicateMatcher<TypePredicate> typePredicate(String namespacePrefix, String localName) {
+    public static PredicateMatcher<TypePredicate> typePredicate(String namespace, String localName) {
         PredicateMatcher<TypePredicate> m = new PredicateMatcher<TypePredicate>(TypePredicate.class);
-        m.addRequiredProperty("namespacePrefix", equalTo(namespacePrefix));
+        m.addRequiredProperty("namespace", equalTo(namespace));
         m.addRequiredProperty("localName", equalTo(localName));
         return m;
     }
diff --git a/src/test/java/au/com/miskinhill/rdftemplate/selector/SelectorEvaluationUnitTest.java b/src/test/java/au/com/miskinhill/rdftemplate/selector/SelectorEvaluationUnitTest.java
@@ -16,6 +16,7 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import au.com.miskinhill.rdftemplate.TestNamespacePrefixMap;
 import au.com.miskinhill.rdftemplate.datatype.DateDataType;
 import au.com.miskinhill.rdftemplate.datatype.DateTimeDataType;
 
@@ -23,7 +24,7 @@ public class SelectorEvaluationUnitTest {
     
     private Model m;
     private Resource journal, issue, article, citedArticle, author, anotherAuthor, book, review, anotherReview, obituary, en, ru, forum;
-    private SelectorFactory selectorFactory;
+    private AntlrSelectorFactory selectorFactory;
     
     @BeforeClass
     public static void ensureDatatypesRegistered() {
@@ -50,6 +51,7 @@ public class SelectorEvaluationUnitTest {
         ru = m.createResource("http://www.lingvoj.org/lang/ru");
         forum = m.createResource("http://miskinhill.com.au/");
         selectorFactory = new AntlrSelectorFactory();
+        selectorFactory.setNamespacePrefixMap(TestNamespacePrefixMap.getInstance());
     }
     
     @Test
diff --git a/src/test/java/au/com/miskinhill/rdftemplate/selector/SelectorParserUnitTest.java b/src/test/java/au/com/miskinhill/rdftemplate/selector/SelectorParserUnitTest.java
@@ -1,54 +1,60 @@
 package au.com.miskinhill.rdftemplate.selector;
 
+import static au.com.miskinhill.rdftemplate.TestNamespacePrefixMap.MHS_NS;
 import static au.com.miskinhill.rdftemplate.selector.AdaptationMatcher.*;
 import static au.com.miskinhill.rdftemplate.selector.PredicateMatcher.*;
-import static au.com.miskinhill.rdftemplate.selector.SelectorMatcher.*;
 import static au.com.miskinhill.rdftemplate.selector.SelectorComparatorMatcher.*;
+import static au.com.miskinhill.rdftemplate.selector.SelectorMatcher.*;
 import static au.com.miskinhill.rdftemplate.selector.TraversalMatcher.*;
 import static org.junit.Assert.*;
 
-import org.junit.Before;
-
 import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.sparql.vocabulary.FOAF;
+import com.hp.hpl.jena.vocabulary.DCTerms;
+import com.hp.hpl.jena.vocabulary.RDF;
+import org.junit.Before;
 import org.junit.Test;
 
+import au.com.miskinhill.rdftemplate.TestNamespacePrefixMap;
+
 public class SelectorParserUnitTest {
     
-    private SelectorFactory factory;
+    private AntlrSelectorFactory factory;
     
     @Before
     public void setUp() {
         factory = new AntlrSelectorFactory();
+        factory.setNamespacePrefixMap(TestNamespacePrefixMap.getInstance());
     }
     
     @Test
     public void shouldRecogniseSingleTraversal() throws Exception {
         Selector<RDFNode> selector = factory.get("dc:creator").withResultType(RDFNode.class);
-        assertThat(selector, selector(traversal("dc", "creator")));
+        assertThat(selector, selector(traversal(DCTerms.NS, "creator")));
     }
     
     @Test
     public void shouldRecogniseMultipleTraversals() throws Exception {
         Selector<RDFNode> selector = factory.get("dc:creator/foaf:name").withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("dc", "creator"),
-                traversal("foaf", "name")));
+                traversal(DCTerms.NS, "creator"),
+                traversal(FOAF.NS, "name")));
     }
     
     @Test
     public void shouldRecogniseInverseTraversal() throws Exception {
         Selector<RDFNode> selector = factory.get("!dc:isPartOf/!dc:isPartOf").withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("dc", "isPartOf").inverse(),
-                traversal("dc", "isPartOf").inverse()));
+                traversal(DCTerms.NS, "isPartOf").inverse(),
+                traversal(DCTerms.NS, "isPartOf").inverse()));
     }
     
     @Test
     public void shouldRecogniseSortOrder() throws Exception {
         Selector<RDFNode> selector = factory.get("!mhs:isIssueOf(mhs:publicationDate#comparable-lv)").withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("mhs", "isIssueOf").inverse()
-                .withSortOrder(selectorComparator(selector(traversal("mhs", "publicationDate"))
+                traversal(MHS_NS, "isIssueOf").inverse()
+                .withSortOrder(selectorComparator(selector(traversal(MHS_NS, "publicationDate"))
                     .withAdaptation(comparableLVAdaptation())))));
     }
     
@@ -56,8 +62,8 @@ public class SelectorParserUnitTest {
     public void shouldRecogniseReverseSortOrder() throws Exception {
         Selector<RDFNode> selector = factory.get("!mhs:isIssueOf(~mhs:publicationDate#comparable-lv)").withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("mhs", "isIssueOf").inverse()
-                .withSortOrder(selectorComparator(selector(traversal("mhs", "publicationDate"))
+                traversal(MHS_NS, "isIssueOf").inverse()
+                .withSortOrder(selectorComparator(selector(traversal(MHS_NS, "publicationDate"))
                     .withAdaptation(comparableLVAdaptation())).reversed())));
     }
     
@@ -65,8 +71,8 @@ public class SelectorParserUnitTest {
     public void shouldRecogniseComplexSortOrder() throws Exception {
         Selector<RDFNode> selector = factory.get("!mhs:reviews(dc:isPartOf/mhs:publicationDate#comparable-lv)").withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("mhs", "reviews")
-                .withSortOrder(selectorComparator(selector(traversal("dc", "isPartOf"), traversal("mhs", "publicationDate"))
+                traversal(MHS_NS, "reviews")
+                .withSortOrder(selectorComparator(selector(traversal(DCTerms.NS, "isPartOf"), traversal(MHS_NS, "publicationDate"))
                         .withAdaptation(comparableLVAdaptation())))));
     }
     
@@ -74,7 +80,7 @@ public class SelectorParserUnitTest {
     public void shouldRecogniseUriAdaptation() throws Exception {
         Selector<?> selector = factory.get("mhs:coverThumbnail#uri");
         assertThat(selector, selector(
-                traversal("mhs", "coverThumbnail"))
+                traversal(MHS_NS, "coverThumbnail"))
                 .withAdaptation(uriAdaptation()));
     }
     
@@ -88,7 +94,7 @@ public class SelectorParserUnitTest {
     public void shouldRecogniseUriSliceAdaptation() throws Exception {
         Selector<?> selector = factory.get("dc:identifier[uri-prefix='urn:issn:']#uri-slice(9)");
         assertThat(selector, selector(
-                traversal("dc", "identifier")
+                traversal(DCTerms.NS, "identifier")
                     .withPredicate(uriPrefixPredicate("urn:issn:")))
                 .withAdaptation(uriSliceAdaptation(9)));
     }
@@ -99,10 +105,10 @@ public class SelectorParserUnitTest {
                 "!mhs:isIssueOf[uri-prefix='http://miskinhill.com.au/journals/'](~mhs:publicationDate#comparable-lv)")
                 .withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("mhs", "isIssueOf")
+                traversal(MHS_NS, "isIssueOf")
                     .inverse()
                     .withPredicate(uriPrefixPredicate("http://miskinhill.com.au/journals/"))
-                    .withSortOrder(selectorComparator(selector(traversal("mhs", "publicationDate"))
+                    .withSortOrder(selectorComparator(selector(traversal(MHS_NS, "publicationDate"))
                             .withAdaptation(comparableLVAdaptation())).reversed())));
     }
     
@@ -112,12 +118,12 @@ public class SelectorParserUnitTest {
                 "!mhs:isIssueOf(~mhs:publicationDate#comparable-lv)[0]/mhs:coverThumbnail#uri")
                 .withResultType(String.class);
         assertThat(selector, selector(
-                traversal("mhs", "isIssueOf")
+                traversal(MHS_NS, "isIssueOf")
                     .inverse()
-                    .withSortOrder(selectorComparator(selector(traversal("mhs", "publicationDate"))
+                    .withSortOrder(selectorComparator(selector(traversal(MHS_NS, "publicationDate"))
                             .withAdaptation(comparableLVAdaptation())).reversed())
                     .withSubscript(0),
-                traversal("mhs", "coverThumbnail"))
+                traversal(MHS_NS, "coverThumbnail"))
                 .withAdaptation(uriAdaptation()));
     }
     
@@ -125,8 +131,8 @@ public class SelectorParserUnitTest {
     public void shouldRecogniseLVAdaptation() throws Exception {
         Selector<Object> selector = factory.get("dc:language/lingvoj:iso1#lv").withResultType(Object.class);
         assertThat(selector, selector(
-                traversal("dc", "language"),
-                traversal("lingvoj", "iso1"))
+                traversal(DCTerms.NS, "language"),
+                traversal("http://www.lingvoj.org/ontology#", "iso1"))
                 .withAdaptation(lvAdaptation()));
     }
     
@@ -134,16 +140,16 @@ public class SelectorParserUnitTest {
     public void shouldRecogniseTypePredicate() throws Exception {
         Selector<RDFNode> selector = factory.get("!dc:creator[type=mhs:Review]").withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("dc", "creator").inverse().withPredicate(typePredicate("mhs", "Review"))));
+                traversal(DCTerms.NS, "creator").inverse().withPredicate(typePredicate(MHS_NS, "Review"))));
     }
     
     @Test
     public void shouldRecogniseAndCombinationOfPredicates() throws Exception {
         Selector<RDFNode> selector = factory.get("!dc:creator[type=mhs:Review and uri-prefix='http://miskinhill.com.au/journals/']").withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("dc", "creator").inverse()
+                traversal(DCTerms.NS, "creator").inverse()
                 .withPredicate(booleanAndPredicate(
-                    typePredicate("mhs", "Review"),
+                    typePredicate(MHS_NS, "Review"),
                     uriPrefixPredicate("http://miskinhill.com.au/journals/")))));
     }
     
@@ -151,25 +157,25 @@ public class SelectorParserUnitTest {
     public void shouldRecogniseUnion() throws Exception {
         Selector<RDFNode> selector = factory.get("!dc:creator | !mhs:translator").withResultType(RDFNode.class);
         assertThat((UnionSelector<RDFNode>) selector, unionSelector(
-                selector(traversal("dc", "creator").inverse()),
-                selector(traversal("mhs", "translator").inverse())));
+                selector(traversal(DCTerms.NS, "creator").inverse()),
+                selector(traversal(MHS_NS, "translator").inverse())));
     }
     
     @Test
     public void shouldRecogniseMultipleSortSelectors() throws Exception {
         Selector<RDFNode> selector = factory.get("!dc:creator(~dc:isPartOf/mhs:publicationDate#comparable-lv,mhs:startPage#comparable-lv)").withResultType(RDFNode.class);
         assertThat(selector, selector(
-                traversal("dc", "creator").inverse()
+                traversal(DCTerms.NS, "creator").inverse()
                 .withSortOrder(
-                    selectorComparator(selector(traversal("dc", "isPartOf"), traversal("mhs", "publicationDate"))
+                    selectorComparator(selector(traversal(DCTerms.NS, "isPartOf"), traversal(MHS_NS, "publicationDate"))
                         .withAdaptation(comparableLVAdaptation())).reversed(),
-                    selectorComparator(selector(traversal("mhs", "startPage")).withAdaptation(comparableLVAdaptation())))));
+                    selectorComparator(selector(traversal(MHS_NS, "startPage")).withAdaptation(comparableLVAdaptation())))));
     }
     
     @Test
     public void shouldRecogniseFormattedDTAdaptation() throws Exception {
         Selector<?> selector = factory.get("dc:created#formatted-dt('d MMMM yyyy')");
-        assertThat(selector, selector(traversal("dc", "created"))
+        assertThat(selector, selector(traversal(DCTerms.NS, "created"))
                 .withAdaptation(formattedDTAdaptation("d MMMM yyyy")));
     }
     
@@ -177,7 +183,7 @@ public class SelectorParserUnitTest {
     public void shouldRecogniseRdfType() throws Exception {
         // was broken due to ANTLR being confused about the literal string "type" which was hardcoded to be a predicate
         Selector<RDFNode> selector = factory.get("rdf:type").withResultType(RDFNode.class);
-        assertThat(selector, selector(traversal("rdf", "type")));
+        assertThat(selector, selector(traversal(RDF.getURI(), "type")));
     }
     
     @Test(expected = InvalidSelectorSyntaxException.class)
diff --git a/src/test/java/au/com/miskinhill/rdftemplate/selector/TraversalMatcher.java b/src/test/java/au/com/miskinhill/rdftemplate/selector/TraversalMatcher.java
@@ -14,9 +14,9 @@ public class TraversalMatcher extends BeanPropertyMatcher<Traversal> {
         super(Traversal.class);
     }
     
-    public static TraversalMatcher traversal(String propertyNamespacePrefix, String propertyLocalName) {
+    public static TraversalMatcher traversal(String propertyNamespace, String propertyLocalName) {
         TraversalMatcher m = new TraversalMatcher();
-        m.addRequiredProperty("propertyNamespacePrefix", equalTo(propertyNamespacePrefix));
+        m.addRequiredProperty("propertyNamespace", equalTo(propertyNamespace));
         m.addRequiredProperty("propertyLocalName", equalTo(propertyLocalName));
         return m;
     }
diff --git a/src/test/resources/au/com/miskinhill/rdftemplate/test-data.xml b/src/test/resources/au/com/miskinhill/rdftemplate/test-data.xml
@@ -43,7 +43,7 @@
     <dc:description rdf:parseType="Literal"><div xmlns="http://www.w3.org/1999/xhtml" lang="en"><p><em>Test Journal</em> is a journal.</p></div></dc:description>
     <dc:language rdf:resource="http://www.lingvoj.org/lang/en" />
     <dc:language rdf:resource="http://www.lingvoj.org/lang/ru" />
-    <mhs:beginningDate>1987</mhs:beginningDate>
+    <mhs:beginningDate rdf:datatype="http://www.w3.org/TR/xmlschema-2/#date">1987</mhs:beginningDate>
   </mhs:Journal>
   <lingvoj:Lingvo rdf:about="http://www.lingvoj.org/lang/en">
     <lingvoj:iso1>en</lingvoj:iso1>