本文整理汇总了Java中org.apache.jena.graph.NodeFactory类的典型用法代码示例。如果您正苦于以下问题:Java NodeFactory类的具体用法?Java NodeFactory怎么用?Java NodeFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NodeFactory类属于org.apache.jena.graph包,在下文中一共展示了NodeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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;
}
示例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));
}
示例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()) ;
}
示例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);
}
示例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);
});
}
示例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;
}
示例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());
}