本文整理汇总了Java中org.apache.jena.rdf.model.Literal.getLexicalForm方法的典型用法代码示例。如果您正苦于以下问题:Java Literal.getLexicalForm方法的具体用法?Java Literal.getLexicalForm怎么用?Java Literal.getLexicalForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.Literal
的用法示例。
在下文中一共展示了Literal.getLexicalForm方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildNext
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
@Override
protected Indexable buildNext(Statement statement) {
InstanceEntity instanceEntity = createInstance(applyNS(statement.getSubject().getURI()));
PropertyEntity propertyEntity = createProperty(applyNS(statement.getPredicate().getURI()));
LabeledEntity labeledEntity;
if (!statement.getObject().isLiteral()) {
//Is created as an instance but can be changed to a class down on the workflow in EntityClassifierProcessor.
labeledEntity = createInstance(applyNS(statement.getObject().asResource().getURI()));
} else {
Literal literal = statement.getObject().asLiteral();
String dataType = literal.getDatatypeURI();
String langTag = literal.getLanguage();
String value = literal.getLexicalForm();
labeledEntity = new ValueEntity(value, dataType, langTag);
}
return new Indexable(new Fact(kbId, instanceEntity, propertyEntity, labeledEntity), kbId);
}
示例2: getLabelFromLinkedData
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
/**
* Dereference the IRI and look for label property value.
* @param iri the IRI
* @return the label if exist, otherwise <code>null</code>
*/
private String getLabelFromLinkedData(String iri){
logger.debug("Get label for " + iri + " from Linked Data...");
try {
// 1. get triples for the IRI by sending a Linked Data request
Model model = uriDereferencer.dereference(iri);
// 2. check if we find a label in the triples
for (String labelProperty : labelProperties) {
for(Statement st : model.listStatements(model.getResource(iri), model.getProperty(labelProperty), (RDFNode)null).toList()){
Literal literal = st.getObject().asLiteral();
// language check
String language = literal.getLanguage();
if(language != null && language.equals(this.language)){
return literal.getLexicalForm();
}
}
}
} catch (DereferencingFailedException e) {
logger.error(e.getMessage(), e);
}
return null;
}
示例3: formatNode
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
public static String formatNode(RDFNode node) {
if (node.isURIResource()) {
return "<" + node.asResource().getURI().trim().replace(" ", "") + ">";
}
if (node.isLiteral()){
Literal value = node.asLiteral();
String formattedValue = "\"" + value.getLexicalForm() + "\"";
if (!value.getLanguage().isEmpty()) {
formattedValue += "@" + value.getLanguage() ;
}
if (!value.getDatatypeURI().isEmpty()
&& !value.getDatatypeURI().endsWith("langString")
&& !value.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
formattedValue += "^^<" + value.getDatatypeURI() + ">" ;
}
return formattedValue;
}
throw new IllegalArgumentException("cannot support blank nodes as targets");
}
示例4: testSimpleDiff
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
@Test
public void testSimpleDiff() throws Exception {
Model model2 = hydrateAndModifySecondModel();
String sparql = DiffToSparqlInsertUpdateBuilder.buildSparqlInsertUpdate(
RDFDifferenceBuilder.buildDifference(model, model2));
System.out.println(sparql);
assertTrue(sparql.startsWith("DELETE"));
Resource res2 = model2.createResource("http://example/com/Playpen2#foobarFoo");
StmtIterator it = model2.listStatements(res2, prop1, (RDFNode) null);
Statement stmt = it.nextStatement();
assertTrue(stmt.getObject().asLiteral().getBoolean() == false);
it = model2.listStatements(res2, prop2, (RDFNode) null);
stmt = it.nextStatement();
assertTrue(stmt.getObject().asLiteral().getLong() == 1);
it = model2.listStatements(res2, prop3, (RDFNode) null);
stmt = it.nextStatement();
XSDDateTime date = (XSDDateTime) stmt.getObject().asLiteral().getValue();
it = model2.listStatements(res2, prop4, (RDFNode) null);
stmt = it.nextStatement();
Literal lit = stmt.getObject().asLiteral();
String val = lit.getLexicalForm();
String dataType = lit.getDatatype().getURI();
assertTrue(val.equals("2017-01-01"));
assertTrue(dataType.equals(XSDDatatype.XSDdate.getURI()));
it = model2.listStatements(res2, prop5, (RDFNode) null);
stmt = it.nextStatement();
assertTrue(stmt.getObject().asLiteral().getString().equals("http://www.google.com"));
assertTrue(stmt.getObject().asLiteral().getDatatype().getURI().equals(XSDDatatype.XSDanyURI.getURI()));
}
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:37,代码来源:DiffToSparqlInsertUpdateBuilderTests.java
示例5: getNodeValue
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
private static String getNodeValue(RDFNode node) {
if (node.isLiteral()) {
Literal lit = node.asLiteral();
return lit.getLexicalForm();
}
if (node.isResource()) {
Resource res = node.asResource();
return res.getURI();
}
throw new RuntimeException("RDF node " + node + " is neither a literal nor a resource!");
}
示例6: getLabelFromLinkedData
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
/**
* Dereference the IRI and look for label property value.
*
* @param iri
* the IRI
* @return the label if exist, otherwise <code>null</code>
*/
private String getLabelFromLinkedData(String iri) {
logger.debug("Get label for " + iri + " from Linked Data...");
try {
// 1. get triples for the IRI by sending a Linked Data request
Model model = uriDereferencer.dereference(iri);
// 2. check if we find a label in the triples
for (String labelProperty : labelProperties) {
for (Statement st : model
.listStatements(model.getResource(iri), model.getProperty(labelProperty), (RDFNode) null)
.toList()) {
Literal literal = st.getObject().asLiteral();
// language check
String language = literal.getLanguage();
if (language != null && language.equals(this.language)) {
return literal.getLexicalForm();
}
}
}
} catch (DereferencingFailedException e) {
logger.error(e.getMessage(), e);
}
return null;
}
示例7: withSubstitutions
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
public static Literal withSubstitutions(Literal template, QuerySolution bindings, Function<RDFNode,String> labelFunction) {
StringBuffer buffer = new StringBuffer();
String labelTemplate = template.getLexicalForm();
for(int i = 0; i < labelTemplate.length(); i++) {
if(i < labelTemplate.length() - 3 && labelTemplate.charAt(i) == '{' && (labelTemplate.charAt(i + 1) == '?' || labelTemplate.charAt(i + 1) == '$')) {
int varEnd = i + 2;
while(varEnd < labelTemplate.length()) {
if(labelTemplate.charAt(varEnd) == '}') {
String varName = labelTemplate.substring(i + 2, varEnd);
RDFNode varValue = bindings.get(varName);
if(varValue != null) {
if(labelFunction != null) {
buffer.append(labelFunction.apply(varValue));
}
else if(varValue instanceof Resource) {
buffer.append(RDFLabels.get().getLabel((Resource)varValue));
}
else if(varValue instanceof Literal) {
buffer.append(varValue.asNode().getLiteralLexicalForm());
}
}
break;
}
else {
varEnd++;
}
}
i = varEnd;
}
else {
buffer.append(labelTemplate.charAt(i));
}
}
if(template.getLanguage().isEmpty()) {
return ResourceFactory.createTypedLiteral(buffer.toString());
}
else {
return ResourceFactory.createLangLiteral(buffer.toString(), template.getLanguage());
}
}
示例8: RegisterEntryInfo
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
public RegisterEntryInfo(Resource status, Resource item, Resource entity, Literal label, Resource type, Literal notation) {
this.status = Status.forResource(status);
this.itemURI = item.getURI();
this.entityURI = entity.getURI();
this.labels.add( label );
this.types.add( type );
this.notation = notation == null ? null : notation.getLexicalForm();
}
示例9: encode
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
public static String encode(RDFNode value, PrefixMapping prefixes, boolean embedded, Set<Resource> seen) {
if (value.isResource()) {
Resource r = value.asResource();
if (value.isURIResource()) {
return asPrefixOrURI( r.getURI(), prefixes);
} else {
return serializeBnode(r, prefixes, seen);
}
} else {
Literal l = value.asLiteral();
String lex = l.getLexicalForm();
if (l.getLanguage() == null || l.getLanguage().isEmpty()) {
if (l.getDatatype() == null || l.getDatatypeURI().equals(XSD.xstring.getURI())) {
if (embedded) {
if (lex.contains("\n")) {
return "'''" + lex + "'''";
} else {
return "'" + lex.replace("'", "\\'") + "'";
}
} else {
if (TRAP_PATTERN.matcher(lex).matches() || lex.contains(VALUE_SEP)) {
// String that looks like a number or boolean so quote it
return "'" + lex.replace("'", "\\'") + "'";
} else {
return lex;
}
}
} else {
String dt = l.getDatatypeURI();
for (String nt : NUMERIC_TYPES) {
if (dt.equals(nt)) {
return l.getLexicalForm(); // Treat numbers as plain, means round trip isn't safe TODO Review this
}
}
return String.format("'%s'^^%s", lex, asPrefixOrURI(dt, prefixes));
}
} else {
return String.format("'%s'@%s", lex, l.getLanguage());
}
}
}