本文整理汇总了Java中org.apache.jena.rdf.model.Literal.getLanguage方法的典型用法代码示例。如果您正苦于以下问题:Java Literal.getLanguage方法的具体用法?Java Literal.getLanguage怎么用?Java Literal.getLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.Literal
的用法示例。
在下文中一共展示了Literal.getLanguage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: parse
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
@Override
public RDFDataset parse(Object input) throws JsonLdError {
RDFDataset dataset = new RDFDataset();
Model m = (Model)input;
for (StmtIterator i = m.listStatements(); i.hasNext(); ) {
Statement stmt = i.next();
String s = idForResource( stmt.getSubject() );
String p = idForResource( stmt.getPredicate() );
RDFNode o = stmt.getObject();
if( o.isLiteral() ) {
Literal l = o.asLiteral();
String lang = l.getLanguage();
if (lang != null && lang.length() == 0) {
lang = null ;
}
String dt = l.getDatatypeURI();
if (dt == null ) {
dt = XSDDatatype.XSDstring.getURI() ;
}
dataset.addTriple(s, p, l.getLexicalForm(), dt, lang);
} else {
dataset.addTriple(s, p, idForResource( o.asResource() ));
}
}
return dataset;
}
示例4: 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");
}
示例5: 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;
}
示例6: 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());
}
}
}