我正在尝试使用我的数据库进行映射。我正在使用 Jena 和 D2RQ 引擎。
我不知道如何使用有关与数据库连接的信息配置文件 .ttl。
这是我的代码:
public class CreateOntModel5 {
public static void main(String[] args) throws OWLOntologyStorageException,
OWLOntologyCreationException, IOException, SQLException {
// Set up the ModelD2RQ using a mapping file
Model m = new ModelD2RQ("C:/Users/Tiziano/workspace/rules/prova0-mappings.ttl");
// Find anything with an rdf:type of iswc:InProceedings
StmtIterator paperIt = m.listStatements(null, RDF.type, ISWC.InProceedings);
// List found papers and print their titles
while (paperIt.hasNext()) {
Resource paper = paperIt.nextStatement().getSubject();
System.out.println("Paper: " + paper.getProperty(DC.title).getString());
// List authors of the paper and print their names
StmtIterator authorIt = paper.listProperties(DC.creator);
while (authorIt.hasNext()) {
Resource author = authorIt.nextStatement().getResource();
System.out.println("Author: " + author.getProperty(FOAF.name).getString());
}
System.out.println();
}
m.close();
}
}
在这里您可以找到映射文件代码:
@prefix sdb: <http://jena.hpl.hp.com/2007/sdb#> .
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352#> .
@base <http://example.com/base/> .
:myModel
a d2rq:D2RQModel;
d2rq:mappingFile <prova0-mappings.ttl>;
d2rq:resourceBaseURI <http://localhost:3306/prova_rules>;
.
<MAPPING-ID1>
a rr:TriplesMap;
rr:logicalTable [ rr:tableName "esame"] ;
rr:subjectMap [ rr:template "http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352/scrittura/campowrite1={\"campowrite1\"}";
rr:class <http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352/scrittura>
];
rr:predicateObjectMap [
rr:predicate <http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352/scrittura#campowrite1> ;
rr:objectMap [ rr:column "\"campowrite1\""; rr:datatype <http://www.w3.org/2001/XMLSchema#integer> ]
];
rr:predicateObjectMap [
rr:predicate <http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352/scrittura#campowrite2> ;
rr:objectMap [ rr:column "\"campowrite2\"" ]
].
我认为错误出在 ttl 文件上。
错误是:
Exception in thread "main" com.hp.hpl.jena.n3.turtle.TurtleParseException: Line 11, column 7: Unresolved prefixed name: d2rq:D2RQModel
at com.hp.hpl.jena.n3.turtle.ParserBase.throwParseException(ParserBase.java:274)
at com.hp.hpl.jena.n3.turtle.ParserBase.resolvePName(ParserBase.java:195)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.PrefixedName(TurtleParser.java:680)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.IRIref(TurtleParser.java:664)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.GraphTerm(TurtleParser.java:475)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.VarOrTerm(TurtleParser.java:399)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.GraphNode(TurtleParser.java:362)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.Object(TurtleParser.java:215)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.ObjectList(TurtleParser.java:197)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.PropertyListNotEmpty(TurtleParser.java:165)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.TriplesSameSubject(TurtleParser.java:130)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.Statement(TurtleParser.java:76)
at com.hp.hpl.jena.n3.turtle.parser.TurtleParser.parse(TurtleParser.java:46)
at com.hp.hpl.jena.n3.turtle.ParserTurtle.parse(ParserTurtle.java:37)
at com.hp.hpl.jena.n3.turtle.TurtleReader.readWorker(TurtleReader.java:21)
at com.hp.hpl.jena.n3.JenaReaderBase.readImpl(JenaReaderBase.java:101)
at com.hp.hpl.jena.n3.JenaReaderBase.read(JenaReaderBase.java:68)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:226)
at com.hp.hpl.jena.util.FileManager.readModelWorker(FileManager.java:395)
at com.hp.hpl.jena.util.FileManager.loadModelWorker(FileManager.java:299)
at com.hp.hpl.jena.util.FileManager.loadModel(FileManager.java:250)
at de.fuberlin.wiwiss.d2rq.jena.ModelD2RQ.<init>(ModelD2RQ.java:35)
at src.jenalib.CreateOntModel5.main(CreateOntModel5.java:28)
我想我在 ttl 文件中做错了什么,但我不知道是什么。有什么帮助吗?
谢谢你。