本文整理汇总了Java中org.apache.jena.rdf.model.Literal.getDatatypeURI方法的典型用法代码示例。如果您正苦于以下问题:Java Literal.getDatatypeURI方法的具体用法?Java Literal.getDatatypeURI怎么用?Java Literal.getDatatypeURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.Literal
的用法示例。
在下文中一共展示了Literal.getDatatypeURI方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getDeduplication
import org.apache.jena.rdf.model.Literal; //导入方法依赖的package包/类
private Set<String> getDeduplication(StringBuilder builder, Triple[] triples) {
// Deduplicate with HashSet
Set<String> deduplicate = new HashSet<String>();
for (Triple triple : triples) {
StringBuilder builder2 = new StringBuilder();
builder2.append(" <").append(resource).append(triple.getSubject()).append("> ");
deduplicate.add(builder.toString() + builder2.toString());
builder2.append(" <").append(properties).append(triple.getPredicate()).append("> ");
if (triple.isObjectResource()) {
builder2.append(" <").append(resource).append(triple.getObject()).append("> ");
} else {
Model empty = ModelFactory.createDefaultModel();
Literal l = empty.createTypedLiteral(triple.getObject());
String obj = "\"" + l.getValue() + "\"^^<" + l.getDatatypeURI() + ">";
builder2.append(obj);
}
deduplicate.add(builder2.toString());
}
return deduplicate;
}
示例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: 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());
}
}
}