如何从本体中检索基本和推断语句(主语,谓语,对象)?

时间:2016-02-19 18:41:25

标签: java rdf jena semantic-web ontology

我正在使用http://quranontology.com/Concept中的古兰经ontolology。我正在为此目的使用jena 到目前为止,我在语句中得到null和一些奇怪的值。这就是我得到的。

null    subClassOf     http://www.w3.org/2000/01/rdf-schema#Resource
null    type     http://www.w3.org/2000/01/rdf-schema#Class
Verse    subClassOf     http://www.w3.org/2000/01/rdf-schema#Resource
Verse    type     http://www.w3.org/2000/01/rdf-schema#Class
null    subClassOf     http://www.w3.org/2000/01/rdf-schema#Resource
null    type     http://www.w3.org/2000/01/rdf-schema#Class
subject    type     http://www.w3.org/1999/02/22-rdf-syntax-ns#Property
subject    domain     http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement
subject    subPropertyOf     http://www.w3.org/1999/02/22-rdf-syntax-ns#subject
Literal    type     http://www.w3.org/2000/01/rdf-schema#Class
Literal    subClassOf     http://www.w3.org/2000/01/rdf-schema#Resource
Location    subClassOf     http://www.w3.org/2000/01/rdf-schema#Resource
SecondBlow    type     5ca31608:152fab841db:-7fe2
BrothersOfYusuf    type     5ca31608:152fab841db:-7fe2
Lut    type     5ca31608:152fab841db:-7fe2
Ayyub    type     5ca31608:152fab841db:-7fe2
Al-Safa    type     5ca31608:152fab841db:-7fe2
Cain    type     5ca31608:152fab841db:-7fe2
Harun    type     5ca31608:152fab841db:-7fe2
Wolf    type     5ca31608:152fab841db:-7fe2
Passing-the-Sirat    type     5ca31608:152fab841db:-7fe2
Yusuf    type     5ca31608:152fab841db:-7fe2
Bani-Nadir-Houses    type     5ca31608:152fab841db:-7fe2
Elephant    type     5ca31608:152fab841db:-7fe2
Children-of-Israel    type     5ca31608:152fab841db:-7fe2

注意:我不希望URI只包含在输出中,只需要名称。

我正在运行的代码是;

String fileName = "quran.owl";  
        try {
            File file = new File(fileName);
            FileReader reader = new FileReader(file);
            OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF);                
            model.read(reader, null);
            Iterator iter = model.listStatements();                       
            while (iter.hasNext()) {
                Statement state = (Statement) iter.next();
                if (state != null) {                   
                    System.out.println(state.getSubject().getLocalName() + "    " + 
                            state.getPredicate().getLocalName() 
                            + "     " + state.getObject().toString()
                    );
                }
            }          
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

1 个答案:

答案 0 :(得分:0)

当主题不是空白节点而不是URI时,您将获得null。

块节点没有URI,因此没有本地名称(这是URI的一部分)。