rdfpredicatesesameopenrdf

Check if a predicate is of standard type in Sesame


Is there any possibility in Sesame to check if a Predicate (URI), is w3c standard predicate(RDFS predicates for example) like RDF.TYPE or is included in RDF vocabulary?


Solution

  • You can just compare the namespace part of the IRI to the vocabulary namespace, like so:

    IRI predicate = ... ; // predicate you want to check
    switch (predicate.getNamespace()) {
          case RDF.NAMESPACE: 
                // it's an RDF predicate
                break;
          case RDFS.NAMESPACE: 
                // it's an RDFS predicate
                break;
          ... etc
    }
    

    Of course this won't tell you if the predicate actually exists as part of the RDF/RDFS vocabulary - it merely tells you that its namespace part corresponds. So if your predicate is some made-up property, e.g. http://www.w3.org/1999/02/22-rdf-syntax-ns#foobar, it will also conclude it's part of the RDF namespace: it doesn't verify if the foobar property actually exists in that namespace.

    Check the API Javadoc for a complete overview of all property constants in the RDF and RDFS vocabularies.