0
votes

I have the DBPedia Ontology that I downloaded from http://wiki.dbpedia.org/Downloads39. In this ontology, I have, for example, this situation:

<owl:Class rdf:about="http://dbpedia.org/ontology/BasketballLeague">
        <rdfs:label xml:lang="el">Ομοσπονδία Καλαθοσφαίρισης</rdfs:label><rdfs:label xml:lang="fr">ligue de basketball</rdfs:label><rdfs:label xml:lang="en">basketball league</rdfs:label><rdfs:label xml:lang="it">lega di pallacanestro</rdfs:label><rdfs:label xml:lang="ja">バスケットボールリーグ</rdfs:label><rdfs:comment xml:lang="en">a group of sports teams that compete against each other in Basketball</rdfs:comment><rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/SportsLeague"/>
</owl:Class>

Now, I want to read this ontology using Jena and to retrieve the owl class that has as its object ""ligue de basketball" in French language. I don't know how I can use Jena library to set French language in this case.

From DBPedia Ontology, it seems that xml:lang="fr" is a predicate, but I have tried this code:

String inputFileName = "C:\\dbpedia_3.9.owl";
// Create an empty in-memory ontology model 
OntDocumentManager mgr = new OntDocumentManager();
OntModelSpec s = new OntModelSpec( OntModelSpec.RDFS_MEM );
s.setDocumentManager( mgr );
OntModel m = ModelFactory.createOntologyModel( s, null );
// use the FileManager to open the ontology from the filesystem
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
    throw new IllegalArgumentException( "File: " + inputFileName + " not found"); 
}
// read the ontology file
m.read( in, "" );

StmtIterator stmti = m.listStatements();
            while (stmti.hasNext()){
                Statement statement = stmti.nextStatement();
                System.out.println (statement.getPredicate());
            }

but I get only:

http://www.w3.org/2000/01/rdf-schema#label

I don't get the information on the language in the predicate. Why? How I can retrieve this information and the owl class? What am I doing wrong here?

1
This title is very misleading. You're not asking how to retrieve classes, but how to retrieve the labels of classes in particular language. - Joshua Taylor

1 Answers

2
votes

You need to read up on literals in RDF and how they're encoded in RDF/XML. The ontology snippet you've shown is in RDF/XML (which is not designed to be human readable), and xml:lang is not a property. An xml:lang attribute is used to specify the language of a literal that has a language tag.

2.7 Languages: xml:lang

RDF/XML permits the use of the xml:lang attribute as defined by 2.12 Language Identification of XML 1.0 [XML] to allow the identification of content language. The xml:lang attribute can be used on any node element or property element to indicate that the included content is in the given language. Typed literals which includes XML literals are not affected by this attribute. The most specific in-scope language present (if any) is applied to property element string literal content or property attribute values. The xml:lang="" form indicates the absence of a language identifier.

Some examples of marking content languages for RDF properties are shown in Example 8:

Example 8: Complete example of xml:lang (example08.rdf output example08.nt)

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/">
  <rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">
    <dc:title>RDF/XML Syntax Specification (Revised)</dc:title>
    <dc:title xml:lang="en">RDF/XML Syntax Specification (Revised)</dc:title>
    <dc:title xml:lang="en-US">RDF/XML Syntax Specification (Revised)</dc:title>
  </rdf:Description>

  <rdf:Description rdf:about="http://example.org/buecher/baum" xml:lang="de">
    <dc:title>Der Baum</dc:title>
    <dc:description>Das Buch ist außergewöhnlich</dc:description>
    <dc:title xml:lang="en">The Tree</dc:title>
  </rdf:Description>
</rdf:RDF>

If you look at the example08.nt linked above, you'll see that the triples include:

<http://www.w3.org/TR/rdf-syntax-grammar> <http://purl.org/dc/elements/1.1/title> "RDF/XML Syntax Specification (Revised)" .
<http://www.w3.org/TR/rdf-syntax-grammar> <http://purl.org/dc/elements/1.1/title> "RDF/XML Syntax Specification (Revised)"@en .
<http://www.w3.org/TR/rdf-syntax-grammar> <http://purl.org/dc/elements/1.1/title> "RDF/XML Syntax Specification (Revised)"@en-us .

<http://example.org/buecher/baum> <http://purl.org/dc/elements/1.1/title> "Der Baum"@de .
<http://example.org/buecher/baum> <http://purl.org/dc/elements/1.1/title> "The Tree"@en .

The resources have multiple values for the property dc:title. xml:lang is not a property, but used to specify a part of the literal.

The same thing is true in the DBpedia data. There are multiple values of the property rdfs:label, and the xml:lang attributes in the RDF/XML serialization are used to indicate their language. DBpedia is unavailable to me at the moment, but if you go to http://dbpedia.org/ontology/BasketballLeague and scroll to the bottom of the page, you'll be able to download the data in various formats. If you download it in the TTL/N3 format, you'll see content something like this:

dbpedia-owl:BasketballLeague rdfs:label "basketball league"@en ,
                                        "Ομοσπονδία Καλαθοσφαίρισης""@el ,
                                        "ligue de basketball"@fr, 
                                        ... 

You need to get the object of the predicate with getObject, whether whether it's a literal with isLiteral, and when it is use getLanguage to get the language tag if it has one. The Javadocs for the relevant classes describe all the methods that you'll need. I've linked to the literal class earlier in this paragraph.