-- 作者:kkllyao
-- 发布时间:12/28/2008 5:47:00 PM
-- 用sparql查询owl出现乱码 怎么办啊?
代码我是参考网上的: Model model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null ); model.read("file:./xuexiao.owl"); // null base URI, since model URIs are absolute // Create a new query String queryString = "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#> SELECT ?subject ?object WHERE { ?subject rdfs:subClassOf ?object }"; Query query = QueryFactory.create(queryString); // Execute the query and obtain results QueryExecution qe = QueryExecutionFactory.create(query, model); ResultSet results = qe.execSelect(); // Output query results ResultSetFormatter.out(System.out, results, query); // Important - free up resources used running the query qe.close(); ------------------------------------结果--------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------- | subject | object | =================================================================================================================================== | <http://www.owl-ontologies.com/Ontology1229688475.owl#Professor> | <http://www.owl-ontologies.com/Ontology1229688475.owl#Staff> | | <http://www.owl-ontologies.com/Ontology1229688475.owl#Assistant> | <http://www.owl-ontologies.com/Ontology1229688475.owl#Staff> | | <http://www.owl-ontologies.com/Ontology1229688475.owl#Class> | <http://www.owl-ontologies.com/Ontology1229688475.owl#teach> | | <http://www.owl-ontologies.com/Ontology1229688475.owl#Staff> | <http://www.owl-ontologies.com/Ontology1229688475.owl#teach> | | <http://www.owl-ontologies.com/Ontology1229688475.owl#Course> | <http://www.owl-ontologies.com/Ontology1229688475.owl#teach> | | <http://www.owl-ontologies.com/Ontology1229688475.owl#Course> | _:b0 | | <http://www.owl-ontologies.com/Ontology1229688475.owl#Course> | _:b1 | ---------------------------------------------------------------------------------------------------------------------- owl是: <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns="http://www.owl-ontologies.com/Ontology1229688475.owl#" xml:base="http://www.owl-ontologies.com/Ontology1229688475.owl"> <owl:Ontology rdf:about=""/> <owl:Class rdf:ID="Course"> <rdfs:subClassOf> <owl:Restriction> <owl:allValuesFrom> <owl:Class rdf:ID="Class"/> </owl:allValuesFrom> <owl:onProperty> <owl:ObjectProperty rdf:ID="is_taught_on"/> </owl:onProperty> </owl:Restriction> </rdfs:subClassOf> <rdfs:subClassOf> <owl:Restriction> <owl:allValuesFrom> <owl:Class rdf:ID="Professor"/> </owl:allValuesFrom> <owl:onProperty> <owl:ObjectProperty rdf:ID="is_taught_by"/> </owl:onProperty> </owl:Restriction> </rdfs:subClassOf> <rdfs:subClassOf> <owl:Class rdf:ID="teach"/> </rdfs:subClassOf> </owl:Class> <owl:Class rdf:ID="Staff"> <rdfs:subClassOf rdf:resource="#teach"/> </owl:Class> <owl:Class rdf:about="#Class"> <rdfs:subClassOf rdf:resource="#teach"/> </owl:Class> <owl:Class rdf:ID="Assistant"> <rdfs:subClassOf rdf:resource="#Staff"/> </owl:Class> <owl:Class rdf:about="#Professor"> <rdfs:subClassOf rdf:resource="#Staff"/> </owl:Class> <owl:ObjectProperty rdf:ID="manage"> <rdfs:domain rdf:resource="#Assistant"/> <rdfs:range rdf:resource="#Class"/> </owl:ObjectProperty> <Course rdf:ID="Course_AI"> <is_taught_by> <Professor rdf:ID="Professor_Wang"/> </is_taught_by> <is_taught_on> <Class rdf:ID="Class_00"/> </is_taught_on> </Course> <Class rdf:ID="Class_01"/> <Course rdf:ID="Course_DKK"> <is_taught_by rdf:resource="#Professor_Wang"/> <is_taught_on rdf:resource="#Class_01"/> </Course> <Course rdf:ID="Course_DB"> <is_taught_by> <Professor rdf:ID="Professor_Zhao"/> </is_taught_by> <is_taught_on rdf:resource="#Class_01"/> </Course> <Class rdf:ID="Class_02"/> <Assistant rdf:ID="Assistant_Li"> <manage rdf:resource="#Class_02"/> </Assistant> </rdf:RDF> <!-- Created with Protege (with OWL Plugin 3.3.1, Build 430) http://protege.stanford.edu --> -------------------------------------------- 问题是最后两行应该是:| <http://www.owl-ontologies.com/Ontology1229688475.owl#Course> | is_taught_on only Class | | <http://www.owl-ontologies.com/Ontology1229688475.owl#Course> | is_taught_by only Professor | 这个结果是在protege里面得到的。。但是为什么在这个算法里面就乱码了。。 各位帮忙看一下。谢谢。。 [此贴子已经被作者于2008-12-29 10:10:29编辑过]
|