本文整理汇总了Java中org.apache.jena.graph.impl.LiteralLabel类的典型用法代码示例。如果您正苦于以下问题:Java LiteralLabel类的具体用法?Java LiteralLabel怎么用?Java LiteralLabel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LiteralLabel类属于org.apache.jena.graph.impl包,在下文中一共展示了LiteralLabel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的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));
}
示例2: main
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的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));
}
示例3: main
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的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));
}
示例4: testConvertDate
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的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));
}
示例5: main
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的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));
}
示例6: convert
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
/**
* Convert the literal into natural language.
*
* @param lit
* the literal
* @return the natural language expression
*/
public String convert(LiteralLabel lit) {
logger.debug("Literal to be converted" + lit.toString());
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e.
// omit language tag if
// exists
s = lit.getLexicalForm();
s = s.replaceAll("_", " ");
s = s.replace('*', ' ');
s = s.trim();
if (encapsulateStringLiterals) {
s = '"' + s + '"';
}
} else {// typed literal
if (dt instanceof XSDDatatype) {// built-in XSD datatype
if (dt instanceof XSDAbstractDateTimeType) {// date datetypes
s = convertDateLiteral(lit);
} else if (encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)) {
s = s.replace('*', ' ');
s = s.trim();
s = '"' + s + '"';
}
} else {// user-defined datatype
String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty())
.collect(Collectors.toList()));
s = lit.getLexicalForm() + " " + datatype;
}
}
return s;
}
示例7: convert
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
/**
* Convert the literal into natural language.
* @param lit the literal
* @return the natural language expression
*/
public String convert(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e. omit language tag if exists
s = lit.getLexicalForm();
s = s.replaceAll("_", " ");
if(encapsulateStringLiterals){
s = '"' + s + '"';
}
} else {// typed literal
if (dt instanceof XSDDatatype) {// built-in XSD datatype
if(dt instanceof XSDAbstractDateTimeType){//date datetypes
s = convertDateLiteral(lit);
} else if(encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)){
s = '"' + s + '"';
}
} else {// user-defined datatype
String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty()).collect(Collectors.toList()));
s = lit.getLexicalForm() + " " + datatype;
}
}
return s;
}
示例8: convert
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
/**
* Convert the literal into natural language.
*
* @param lit
* the literal
* @return the natural language expression
*/
public String convert(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e.
// omit language tag if
// exists
s = lit.getLexicalForm();
s = s.replaceAll("_", " ");
if (encapsulateStringLiterals) {
s = '"' + s + '"';
}
} else {// typed literal
if (dt instanceof XSDDatatype) {// built-in XSD datatype
if (dt instanceof XSDAbstractDateTimeType) {// date datetypes
s = convertDateLiteral(lit);
} else if (encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)) {
s = '"' + s + '"';
}
} else {// user-defined datatype
String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty())
.collect(Collectors.toList()));
s = lit.getLexicalForm() + " " + datatype;
}
}
return s;
}
示例9: testConvertUseDefinedDatatype
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
@Test
public void testConvertUseDefinedDatatype() throws Exception {
LiteralLabel lit = NodeFactory
.createLiteral("123", null, new BaseDatatype("http://dbpedia.org/datatypes/squareKilometre"))
.getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
示例10: processLiteralNode
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
public NPPhraseSpec processLiteralNode(Node node) {
LiteralLabel lit = node.getLiteral();
// convert the literal
String literalText = literalConverter.convert(lit);
NPPhraseSpec np = nlgFactory.createNounPhrase(nlgFactory.createWord(literalText, LexicalCategory.NOUN));
np.setPlural(literalConverter.isPlural(lit));
return np;
}
示例11: apply
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
@Override
public Stream<Triple> apply(final Property p) {
try {
final org.apache.jena.graph.Node subject = translator.convert(p.getParent()).asNode();
final org.apache.jena.graph.Node propPredicate = propertyConverter.convert(p).asNode();
final String propertyName = p.getName();
return iteratorToStream(new PropertyValueIterator(p)).filter(this::valueCanBeConverted).map(v -> {
final org.apache.jena.graph.Node object = valueConverter.convert(v).asNode();
if (object.isLiteral()) {
// unpack the name of the property for information about what kind of literal
final int i = propertyName.indexOf('@');
if (i > 0) {
final LiteralLabel literal = object.getLiteral();
final RDFDatatype datatype = literal.getDatatype();
final String datatypeURI = datatype.getURI();
if (datatypeURI.isEmpty() || datatype.equals(XSDstring)) {
// this is an RDF string literal and could involve an RDF lang tag
final String lang = propertyName.substring(i + 1);
final String lex = literal.getLexicalForm();
return create(subject, propPredicate, createLiteral(lex, lang, datatype));
}
}
}
return create(subject, propPredicate, object);
});
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
示例12: getObjectTitle
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
/**
* Get the canonical title of a subject from the graph
*
* @param graph the graph
* @param sub the subject
* @return canonical title of the subject in the graph
*/
public String getObjectTitle(final Graph graph, final Node sub) {
if (sub == null) {
return "";
}
final Optional<String> title = TITLE_PROPERTIES.stream().map(Property::asNode).flatMap(p -> listObjects(
graph, sub, p).toList().stream()).filter(Node::isLiteral).map(Node::getLiteral).map(
LiteralLabel::toString).findFirst();
return title.orElse(sub.isURI() ? sub.getURI() : sub.isBlank() ? sub.getBlankNodeLabel() : sub.toString());
}
示例13: getObjectAsLiteral
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
public LiteralLabel getObjectAsLiteral() {
Node object = triple.getObject();
if (!object.isLiteral()) {
throw new IllegalArgumentException(object + " is NOT a literal.");
}
return object.getLiteral();
}
示例14: getObjectAsLiteralReturnsTheValueAndTypeOfTheObject
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
@Test
public void getObjectAsLiteralReturnsTheValueAndTypeOfTheObject() {
Triple triple = createSingleTripleWithLiteralObject(SUBJECT_URI_NODE, PREDICATE_URI_NODE, OBJECT_LITERAL_NODE);
TripleParser instance = TripleParser.fromTriple(triple);
LiteralLabel value = instance.getObjectAsLiteral();
assertThat(value, allOf(
hasProperty("value", is(OBJECT_VALUE)),
hasProperty("datatype", hasProperty("URI", is(OBJECT_TYPE_URI)))
));
}
示例15: doSparqlQuery
import org.apache.jena.graph.impl.LiteralLabel; //导入依赖的package包/类
private Map<String, List<LabeledEntity>> doSparqlQuery(String sparqlQuery) {
logger.debug(marker, "Executing: {}", sparqlQuery);
long startTime = System.currentTimeMillis();
Map<String, List<LabeledEntity>> result = new LinkedHashMap<>();
EntitySearcher entitySearcher = core.createEntitySearcher();
try (QueryExecution qexec = QueryExecutionFactory.create(sparqlQuery, core.getGraphModel(dbId))) {
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
Binding jBinding = results.nextBinding();
Iterator<Var> vars = jBinding.vars();
while (vars.hasNext()) {
Var jVar = vars.next();
if (!jBinding.get(jVar).isLiteral()) {
String id = jBinding.get(jVar).getURI();
List<LabeledEntity> entities = result.computeIfAbsent(jVar.getVarName(), (v) -> new ArrayList<>());
LabeledEntity labeledEntity = ns.isFromMainNS(id) ? entitySearcher.getEntity(dbId, id) : ModelUtils.createInstance(id);
entities.add(labeledEntity);
} else {
LiteralLabel lit = jBinding.get(jVar).getLiteral();
ValueEntity valueEntity = new ValueEntity(lit.getLexicalForm(), lit.getDatatype().getURI(), lit.language());
result.computeIfAbsent(jVar.getVarName(), (v) -> new ArrayList<>()).add(valueEntity);
}
}
}
}
long millis = System.currentTimeMillis() - startTime;
if (!result.isEmpty()) {
logger.info(marker, "SPARQL {} query took {}s", sparqlQuery, millis / 1000.0);
}
else {
logger.warn(marker, "No matches for {}", sparqlQuery);
}
return result;
}