本文整理汇总了Java中org.apache.jena.graph.NodeFactory类的典型用法代码示例。如果您正苦于以下问题:Java NodeFactory类的具体用法?Java NodeFactory怎么用?Java NodeFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NodeFactory类属于org.apache.jena.graph包,在下文中一共展示了NodeFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: triple
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
public static String triple(String subject, String predicate, String object) throws IOException{
// create the triple we want to convert by using JENA API
Triple t = Triple.create(
NodeFactory.createURI(subject),
NodeFactory.createURI(predicate),
NodeFactory.createURI(object));
// Optionally, we can declare a knowledge base that contains the triple.
// This can be useful during the verbalization process, e.g. the KB could contain labels for entities.
// Here, we use the DBpedia SPARQL endpoint.
SparqlEndpoint endpoint = SparqlEndpoint.create("http://pt.dbpedia.org/sparql", "http://dbpedia.org");
// create the triple converter
TripleConverterPortuguese converter = new TripleConverterPortuguese(endpoint);
// convert the triple into natural language
return converter.convert(t);
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:19,代码来源:RDF2PT.java
示例2: main
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
public static void main(String[] args) {
LiteralConverterPortuguese conv = new LiteralConverterPortuguese(
new DefaultIRIConverterPortuguese(SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
LiteralLabel lit;// = NodeFactory.createLiteralNode("123",
// null,"http://dbpedia.org/datatypes/squareKilometre").getLiteral();
// System.out.println(lit);
// System.out.println(conv.convert(lit));
lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1879-03-14^^http://www.w3.org/2001/XMLSchema#date").getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:23,代码来源:LiteralConverterPortuguese.java
示例3: main
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
public static void main(String[] args) {
LiteralConverter conv = new LiteralConverter(new DefaultIRIConverter(
SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
LiteralLabel lit;// = NodeFactory.createLiteralNode("123", null,"http://dbpedia.org/datatypes/squareKilometre").getLiteral();
// System.out.println(lit);
// System.out.println(conv.convert(lit));
lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:18,代码来源:LiteralConverter.java
示例4: main
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
public static void main(String[] args) {
LiteralConverterFrench conv = new LiteralConverterFrench(
new DefaultIRIConverterPortuguese(SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
LiteralLabel lit;// = NodeFactory.createLiteralNode("123",
// null,"http://dbpedia.org/datatypes/squareKilometre").getLiteral();
// System.out.println(lit);
// System.out.println(conv.convert(lit));
lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1879-03-14^^http://www.w3.org/2001/XMLSchema#date").getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:22,代码来源:LiteralConverterFrench.java
示例5: testPassiveTriples
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testPassiveTriples() throws Exception {
Triple t = Triple.create(NodeFactory.createURI("http://dbpedia.org/resource/Baruch_Spinoza"),
NodeFactory.createURI("http://dbpedia.org/ontology/influenced"),
NodeFactory.createURI("http://dbpedia.org/ontology/Albert_Einstein"));
String text = converter.convert(t);
System.out.println(t + " -> " + text);
// assertEquals("Mathematics of Computation is peer reviewed", text);
t = Triple.create(NodeFactory.createURI("http://dbpedia.org/resource/Baruch_Spinoza"),
NodeFactory.createURI("http://dbpedia.org/ontology/influencedBy"),
NodeFactory.createURI("http://dbpedia.org/ontology/Albert_Einstein"));
text = converter.convert(t);
System.out.println(t + " -> " + text);
// assertEquals("Living Bird is not peer reviewed", text);
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:18,代码来源:TripleConverterTest.java
示例6: testConvertTriplesNoOntology
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testConvertTriplesNoOntology() throws Exception {
TripleConverterPortuguese converter = new TripleConverterPortuguese();
Triple t = Triple.create(NodeFactory.createURI("http://dbpedia.org/resource/Baruch_Spinoza"),
NodeFactory.createURI("http://dbpedia.org/ontology/influenced"),
NodeFactory.createURI("http://dbpedia.org/ontology/Albert_Einstein"));
String text = converter.convert(t);
System.out.println(t + " -> " + text);
// assertEquals("Mathematics of Computation is peer reviewed", text);
t = Triple.create(NodeFactory.createURI("http://dbpedia.org/resource/Baruch_Spinoza"),
NodeFactory.createURI("http://dbpedia.org/ontology/influencedBy"),
NodeFactory.createURI("http://dbpedia.org/ontology/Albert_Einstein"));
text = converter.convert(t);
System.out.println(t + " -> " + text);
// assertEquals("Living Bird is not peer reviewed", text);
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:19,代码来源:TripleConverterTest.java
示例7: testConvertTriplePatterns
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testConvertTriplePatterns() throws Exception {
TripleConverterPortuguese converter = new TripleConverterPortuguese();
Triple t = Triple.create(NodeFactory.createVariable("person"),
NodeFactory.createURI("http://dbpedia.org/ontology/occupation"),
NodeFactory.createURI("http://dbpedia.org/resource/Writer"));
String text = converter.convert(t);
System.out.println(t + " -> " + text);
t = Triple.create(NodeFactory.createURI("http://dbpedia.org/ontology/Albert"),
NodeFactory.createURI("http://dbpedia.org/ontology/occupation"),
NodeFactory.createURI("http://dbpedia.org/resource/Writer"));
SPhraseSpec phrase = converter.convertToPhrase(t, false, false, false);
phrase.getSubject().getChildren().get(0).setFeature(Feature.PRONOMINAL, true);
System.out.println(t + " -> " + r.realise(phrase));
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:19,代码来源:TripleConverterTest.java
示例8: testConvertDate
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
/**
* Test method for
* {@link org.aksw.triple2nl.converter.sparql2nl.naturallanguagegeneration.LiteralConverter#convert(org.apache.jena.rdf.model.Literal)}.
*/
@Test
public void testConvertDate() {
LiteralLabel lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
String convert = conv.convert(lit);
System.out.println(lit + " --> " + convert);
assertEquals("June 27, 1869", convert); // would be with June 27, 1869
// in US
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1989", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
开发者ID:dice-group,项目名称:RDF2PT,代码行数:24,代码来源:LiteralConverterTest.java
示例9: buildConstruct
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
private TripleCollectorBGP buildConstruct(TripleCollectorBGP collector, Element element) {
if (element instanceof ElementGroup) {
for (Element e : ((ElementGroup) element).getElements()) {
buildConstruct(collector, e);
}
return collector;
} else if (element instanceof ElementNamedGraph) {
collector.addTriple(new Triple(((ElementNamedGraph) element).getGraphNameNode(), NodeConst.nodeRDFType, NodeFactory.createURI("https://www.w3.org/TR/sparql11-service-description/#sd-namedGraphs")));
Element namedGraph = ((ElementNamedGraph) element).getElement();
return buildConstruct(collector, namedGraph);
} else if (element instanceof ElementPathBlock) {
ElementPathBlock epb = (ElementPathBlock) element;
List<TriplePath> list = epb.getPattern().getList();
for (TriplePath triplePath : list) {
collector.addTriple(triplePath.asTriple());
}
}
return collector;
}
开发者ID:IBCNServices,项目名称:OBEP,代码行数:20,代码来源:OBEPQueryImpl.java
示例10: main
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
public static void main(String[] args) {
LiteralConverter conv = new LiteralConverter(
new DefaultIRIConverter(SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
LiteralLabel lit;// = NodeFactory.createLiteralNode("123",
// null,"http://dbpedia.org/datatypes/squareKilometre").getLiteral();
// System.out.println(lit);
// System.out.println(conv.convert(lit));
lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
开发者ID:dice-group,项目名称:BENGAL,代码行数:19,代码来源:LiteralConverter.java
示例11: fromThrift
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
public static Node fromThrift(RDF_Term term) {
if ( term.isSetIri() )
return NodeFactory.createURI(term.getIri().getIri()) ;
if ( term.isSetBnode() )
return NodeFactory.createBlankNode(term.getBnode().getLabel()) ;
if ( term.isSetLiteral() ) {
RDF_Literal lit = term.getLiteral() ;
String lex = lit.getLex() ;
String dtString = null ;
if ( lit.isSetDatatype() )
dtString = lit.getDatatype() ;
RDFDatatype dt = NodeFactory.getType(dtString) ;
String lang = lit.getLangtag() ;
return NodeFactory.createLiteral(lex, lang, dt) ;
}
throw new PatchException("No conversion to a Node: "+term.toString()) ;
}
开发者ID:afs,项目名称:rdf-delta,代码行数:22,代码来源:RDFPatchReaderBinary.java
示例12: exec
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Override
public NodeValue exec(NodeValue timeStampValue) {
BigInteger timeStamp;
if (timeStampValue == null || !timeStampValue.isInteger()) {
throw new ExprEvalException("The NodeValue " + timeStampValue + " MUST be an integer."
);
} else {
timeStamp = timeStampValue.getInteger();
}
if (timeStamp.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) != -1) {
throw new ExprEvalException("The NodeValue " + timeStamp + " MUST be less than the biggest long value."
);
} else if (timeStamp.signum() != 1) {
throw new ExprEvalException("The NodeValue " + timeStamp + " MUST be positive."
);
}
Timestamp stamp = new Timestamp(timeStamp.longValue());
Date date = new Date(stamp.getTime());
Node node = NodeFactory.createLiteral(df.format(date), XSDDatatype.XSDdateTime);
return new NodeValueNode(node);
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:26,代码来源:FUN_dateTime.java
示例13: BNodeMap
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
/**
* Constructs a new binding from a query solution.
*
* @param parent -
* @param binding -
*/
public BNodeMap(
final BNodeMap parent,
final BindingHashMapOverwrite binding) {
this(parent);
if (binding == null) {
return;
}
binding.varsList().stream()
.map((v) -> binding.get(v))
.filter((n) -> (n != null && n.isBlank() && !parent.contains(n)))
.forEach((n) -> {
Node bn = NodeFactory.createBlankNode();
bNodeMap.put(n, bn);
});
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:22,代码来源:BNodeMap.java
示例14: next
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Override
public Quad next() {
QuerySolution solution = results.next();
Node s = solution.get("s").asNode();
Node p = solution.get("p").asNode();
Node o = solution.get("o").asNode();
Node g = null;
if (solution.get("g") != null) {
g = solution.get("g").asNode();
} else {
if (graphName != null) {
g = NodeFactory.createURI(graphName);
}
}
Quad quad = new Quad(g, s, p, o);
return quad;
}
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:18,代码来源:QuadsIterator.java
示例15: testWriteableView
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testWriteableView() {
MarkLogicDatasetGraph dsg = getMarkLogicDatasetGraph("testdata/smallfile.nt");
Graph defaultGraph = dsg.getDefaultGraph();
RDFDataMgr.write(System.out, defaultGraph, RDFFormat.TURTLE);
Triple newTriple = Triple.create(NodeFactory.createURI("http://a"),
NodeFactory.createURI("http://b"),
NodeFactory.createLiteral("1", XSDint));
defaultGraph.add(newTriple);
QueryExecution qe = QueryExecutionFactory.create(
"prefix xsd: <http://www.w3.org/2001/XMLSchema#> ask where { <http://a> ?p \"1\"^^xsd:int .}", dsg.toDataset());
assertTrue(qe.execAsk());
defaultGraph.remove(newTriple.getSubject(), newTriple.getPredicate(), newTriple.getObject());
qe = QueryExecutionFactory.create(
"prefix xsd: <http://www.w3.org/2001/XMLSchema#> ask where { <http://a> ?p \"1\"^^xsd:int .}", dsg.toDataset());
assertFalse(qe.execAsk());
}
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:21,代码来源:MarkLogicDatasetGraphTest.java
示例16: testListGraphs_WriteUser
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testListGraphs_WriteUser() throws FileNotFoundException {
// Write New graph with ntriples mimetype & Validate
String file = datasource + "relative1.nt";
// Read triples into dataset
RDFDataMgr.read(markLogicDatasetGraphWriter, file);
markLogicDatasetGraphWriter.sync();
// Add Triples into Named Graph
Graph g = markLogicDatasetGraphWriter.getDefaultGraph();
Node newgraph = NodeFactory.createURI("http://jena.example.org/fileWrite");
markLogicDatasetGraphWriter.addGraph(newgraph, g);
// Get the list of graphs and validate
Iterator<Node> markLogicGraphs = markLogicDatasetGraphWriter.listGraphNodes();
while (markLogicGraphs.hasNext()) {
Node graphs = markLogicGraphs.next();
assertTrue(
"did not find Node in :: " + graphs.toString(),
graphs.toString().contains("http://jena.example.org/fileWrite")
|| graphs.toString().contains(MarkLogicDatasetGraph.DEFAULT_GRAPH_URI)
|| graphs.toString().contains("http://marklogic.com/semantics#graphs"));
}
}
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:26,代码来源:JenaGraphTests.java
示例17: testAdd_ReadUser
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testAdd_ReadUser() throws FileNotFoundException {
Exception exp = null;
try {
Quad quad = new Quad(NodeFactory.createURI("http://originalGraph1"), new Triple(NodeFactory.createURI("#electricVehicle3"),
NodeFactory.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type1"),
NodeFactory.createLiteral("http://people.aifb.kit.edu/awa/2011/smartgrid/schema/smartgrid#ElectricVehicle1")));
markLogicDatasetGraphReader.add(quad);
markLogicDatasetGraphReader.sync();
assertFalse(markLogicDatasetGraphReader.contains(quad));
} catch (Exception e) {
exp = e;
}
assertTrue("Should catch ForbiddenUserException ", exp.toString().contains("ForbiddenUserException") && exp != null);
}
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:18,代码来源:JenaGraphTests.java
示例18: testSetDefaultGraph_admin
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testSetDefaultGraph_admin() {
String file = datasource + "relative1.nt";
// Read triples into dataset
RDFDataMgr.read(markLogicDatasetGraphWriter, file);
markLogicDatasetGraphWriter.sync();
Graph g1 = markLogicDatasetGraphWriter.getDefaultGraph();
assertTrue("did not match Triples", g1.toString().contains("#electricVehicle2"));
// Create New graph and add triples from defaultgraph to new graph
Triple triple = new Triple(NodeFactory.createURI("s5"), NodeFactory.createURI("p5"), NodeFactory.createURI("o5"));
Quad quad = new Quad(NodeFactory.createURI("new-graph-fordefault"), triple);
Node n1 = NodeFactory.createURI("new-graph-fordefault");
markLogicDatasetGraphWriter.add(quad);
markLogicDatasetGraphWriter.sync();
Graph g2 = markLogicDatasetGraphWriter.getGraph(n1);
assertTrue("did not match Triples", g2.contains(triple));
// Set DefaultGraph to be NamedGraph
markLogicDatasetGraphWriter.setDefaultGraph(g2);
Graph defaultG = markLogicDatasetGraphWriter.getDefaultGraph();
assertTrue("did not match Triples", defaultG.contains(triple));
}
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:25,代码来源:JenaGraphTests.java
示例19: testDelete_admin
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testDelete_admin() {
Triple triple = new Triple(NodeFactory.createURI("s5"), NodeFactory.createURI("p5"), NodeFactory.createURI("o5"));
Quad quad = new Quad(NodeFactory.createURI("new-graph-fordefault2"), triple);
Node n2 = NodeFactory.createURI("new-graph-fordefault2");
markLogicDatasetGraphWriter.add(quad);
markLogicDatasetGraphWriter.sync();
Graph g3 = markLogicDatasetGraphWriter.getGraph(n2);
g3.delete(triple);
markLogicDatasetGraphWriter.sync();
assertTrue("did not match Triples", g3.size() == 0);
markLogicDatasetGraphWriter.delete(quad);
assertTrue("Quad Should be deleted , but looks like its not", !markLogicDatasetGraphWriter.contains(quad));
markLogicDatasetGraphWriter.setDefaultGraph(g3);
Graph defaultG = markLogicDatasetGraphWriter.getDefaultGraph();
assertTrue("did not match Triples", defaultG.size() == 0);
}
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:20,代码来源:JenaGraphTests.java
示例20: testStringAskQuery2
import org.apache.jena.graph.NodeFactory; //导入依赖的package包/类
@Test
public void testStringAskQuery2() {
String file = datasource + "tigers.ttl";
// Read triples into dataset
RDFDataMgr.read(markLogicDatasetGraph, file);
markLogicDatasetGraph.sync();
Graph g = markLogicDatasetGraph.getDefaultGraph();
Node newgraph = NodeFactory.createURI("http://marklogic.com/Graph1");
markLogicDatasetGraph.addGraph(newgraph, g);
dataSet = DatasetFactory.create(markLogicDatasetGraph);
String query1 = "ASK FROM <http://marklogic.com/Graph1>" + " WHERE" + " {" + " ?player ?team <#Tigers>." + " }";
QueryExecution queryExec = QueryExecutionFactory.create(query1, dataSet);
Boolean result = queryExec.execAsk();
assertFalse(result);
String query2 = "PREFIX bb: <http://marklogic.com/baseball/players#>" + "PREFIX r: <http://marklogic.com/baseball/rules#>"
+ " ASK WHERE" + " {" + " ?id bb:team r:Tigers." + " ?id bb:position \"pitcher\"." + " }";
queryExec = QueryExecutionFactory.create(query2, dataSet);
assertTrue(queryExec.execAsk());
}
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:24,代码来源:JenaSPARQLUpdateTests.java
注:本文中的org.apache.jena.graph.NodeFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论