本文整理汇总了Java中com.hp.hpl.jena.rdf.model.RDFNode.isLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java RDFNode.isLiteral方法的具体用法?Java RDFNode.isLiteral怎么用?Java RDFNode.isLiteral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.rdf.model.RDFNode
的用法示例。
在下文中一共展示了RDFNode.isLiteral方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeQueryForLong
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public static long executeQueryForLong(String queryString, String serviceEndpoint, String var) {
logger.debug("Executing query: {}", queryString);
//Execute the query
Map<String, RDFNode> nodeMap = executeQueryForMap(queryString, serviceEndpoint, Sets.newHashSet(var));
RDFNode rdfNode = nodeMap.get(var);
if (rdfNode == null) {
throw new IllegalStateException(String.format("The result does not have a binding for the variable '%s' ", var));
}
if (rdfNode.isLiteral()) {
return rdfNode.asLiteral().getLong();
} else {
throw new IllegalStateException(String.format("The binding for the variable '%s' is not a literal", var));
}
}
示例2: toTurtle
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private String toTurtle(RDFNode r) {
if (r.isURIResource()) {
return PrettyPrinter.qNameOrURI(relativize(r.asResource().getURI()), prefixes);
} else if (r.isLiteral()) {
StringBuffer result = new StringBuffer(quote(r.asLiteral().getLexicalForm()));
if (!"".equals(r.asLiteral().getLanguage())) {
result.append("@");
result.append(r.asLiteral().getLanguage());
} else if (r.asLiteral().getDatatype() != null) {
result.append("^^");
result.append(toTurtle(ResourceFactory.createResource(r.asLiteral().getDatatypeURI())));
}
return result.toString();
} else {
if (!blankNodeMap.containsKey(r)) {
blankNodeMap.put(r.asResource(), "_:b" + blankNodeCounter++);
}
return blankNodeMap.get(r);
}
}
示例3: compare
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public int compare(RDFNode n1, RDFNode n2) {
if (n1.isURIResource()) {
if (!n2.isURIResource()) return -1;
return n1.asResource().getURI().compareTo(n2.asResource().getURI());
}
if (n1.isAnon()) {
if (n2.isURIResource()) return 1;
if (n2.isLiteral()) return -1;
return n1.asResource().getId().getLabelString().compareTo(n2.asResource().getId().getLabelString());
}
if (!n2.isLiteral()) return 1;
int cmpLex = n1.asLiteral().getLexicalForm().compareTo(n2.asLiteral().getLexicalForm());
if (cmpLex != 0) return cmpLex;
if (n1.asLiteral().getDatatypeURI() == null) {
if (n2.asLiteral().getDatatypeURI() != null) return -1;
return n1.asLiteral().getLanguage().compareTo(n2.asLiteral().getLanguage());
}
if (n2.asLiteral().getDatatypeURI() == null) return 1;
return n1.asLiteral().getDatatypeURI().compareTo(n2.asLiteral().getDatatypeURI());
}
示例4: writeStatement
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void writeStatement(Statement stmt, PrintStream out)
{
String name = getQName(stmt.getPredicate());
Map<String,String> attrs = null;
String value = null;
RDFNode node = stmt.getObject();
if ( node.isLiteral() )
{
Literal l = node.asLiteral();
value = l.getString();
String lang = l.getLanguage();
if ( !lang.isEmpty() ) { attrs = Collections.singletonMap("xml:lang", lang); }
String datatype = l.getDatatypeURI();
if ( datatype != null ) { attrs = Collections.singletonMap("rdf:datatype", datatype); }
}
else {
attrs = Collections.singletonMap("rdf:resource", getURI(node.asResource()));
}
writeProperty(name, attrs, value, out);
}
示例5: fixLanguage
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public static void fixLanguage(StmtIterator iter, String sLang)
{
if ( (sLang == null) || sLang.trim().isEmpty() ) { return; }
List<Statement> list = iter.toList();
for ( Statement stmt : list )
{
RDFNode n = stmt.getObject();
if ( !n.isLiteral() ) { continue; }
Literal l = n.asLiteral();
String sL = l.getLanguage();
if ( (sL != null) && !sL.trim().isEmpty() ) { continue; }
stmt.changeObject(l.getString(), sLang);
}
}
示例6: binding
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
@Override
public void binding(String varName, RDFNode value) {
// If, for a particular solution, a variable is unbound, no binding element for that variable is included in the result element.
if (value == null)
return;
try {
// start binding element
atts.clear();
atts.addAttribute(dfNamespace, dfAttrVarName, dfAttrVarName, "CDATA", varName);
handler.startElement(dfNamespace, dfBinding, dfBinding, atts);
// binding value
if (value.isLiteral())
literal((Literal) value);
else if (value.isResource())
resource((Resource) value);
// end binding element
handler.endElement(dfNamespace, dfBinding, dfBinding);
} catch (SAXException ex) {
}
}
示例7: getSourceType
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private SourceTypes getSourceType(Resource mappingResource)
{
Property sourceNameProp = model.getProperty(Uris.KM_SOURCE_TYPE_URI);
Statement s = model.getProperty(mappingResource, sourceNameProp);
String sourceType = null;
if(s != null)
{
RDFNode node = s.getObject();
if(node != null && node.isLiteral())
{
sourceType = node.asLiteral().getString();
return SourceTypes.valueOf(sourceType);
}
}
return SourceTypes.CSV;
}
示例8: object
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private String object(RDFNode node) {
if (node.isLiteral()) {
Literal lit = node.asLiteral();
String text = lit.getString();
String lang = lit.getLanguage();
String type = lit.getDatatypeURI();
if (lang == null || "".equals(lang)) {
lang = "";
} else {
lang = " xml:lang='" + escapeXml(lang) + "'";
}
if ("".equals(lang)) {
if (type == null) {
type = "http://www.w3.org/2001/XMLSchema#string";
}
type = " datatype='" + escapeXml(type) + "'";
} else {
type = "";
}
return "<sem:object" + type + lang + ">" + escapeXml(text) + "</sem:object>";
} else if (node.isAnon()) {
return "<sem:object>http://marklogic.com/semantics/blank/" + Long.toHexString(
fuse(scramble((long)node.hashCode()),fuse(scramble(milliSecs),randomValue)))
+"</sem:object>";
} else {
return "<sem:object>" + escapeXml(node.toString()) + "</sem:object>";
}
}
示例9: nodeToString
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private static String nodeToString(RDFNode node) {
if (node.isURIResource()) {
return node.asResource().getURI();
} else if (node.isLiteral()) {
return node.asLiteral().getLexicalForm();
} else {
return node.toString();
}
}
示例10: getShortString
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public static String getShortString(RDFNode node) {
if (node.isLiteral()) {
return node.toString();
} else {
return getShortString(node.asResource());
}
}
示例11: getShortStringWithType
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public static String getShortStringWithType(RDFNode node) {
if (node.isLiteral()) {
return node.asLiteral().getLexicalForm();
} else {
return getShortStringWithType(node.asResource());
}
}
示例12: convertIntoTable
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private static StringMatrix convertIntoTable(
PrefixMapping prefixMap, ResultSet results) {
StringMatrix table = new StringMatrix();
int rowCount = 0;
while (results.hasNext()) {
rowCount++;
QuerySolution soln = results.nextSolution();
Iterator<String> varNames = soln.varNames();
while (varNames.hasNext()) {
String varName = varNames.next();
int colCount = -1;
if (table.hasColumn(varName)) {
colCount = table.getColumnNumber(varName);
} else {
colCount = table.getColumnCount() + 1;
table.setColumnName(colCount, varName);
}
RDFNode node = soln.get(varName);
if (node != null) {
if (node.isResource()) {
Resource resource = (Resource)node;
table.set(rowCount, colCount,
resource.getURI()
);
} else if (node.isLiteral()) {
Literal literal = (Literal)node;
table.set(rowCount, colCount, "" + literal.getValue());
}
}
}
}
return table;
}
示例13: apply
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
@Override
public Optional<String> apply(final Statement input) {
final RDFNode object=input.getObject();
if(object.isLiteral()) {
final Literal literal=object.asLiteral();
if(literal.getDatatypeURI()==null || "http://www.w3.org/2001/XMLSchema#string".equals(literal.getDatatypeURI())) {
return Optional.of(literal.getLexicalForm());
}
}
this.report.warn("Discarding invalid value for property %s: not a String Literal (%s)",input.getPredicate().getURI(),object);
return Optional.absent();
}
示例14: filter
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
@Override
public boolean filter(Resource rsrc)
{
StmtIterator iter = rsrc.listProperties(rsrc.getModel().getProperty(_property));
while ( iter.hasNext() )
{
RDFNode obj = iter.next().getObject();
boolean res = false;
if ( obj.isLiteral() ) { res = filterLiteral(obj.asLiteral()); }
else if ( obj.isURIResource() ) { res = filterResource(obj.asResource()); }
if ( res ) { return true; }
}
return false;
}
示例15: copyFromTdb
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void copyFromTdb( Dataset dataset ) throws RepositoryException {
ValueFactory vf = rc.getValueFactory();
if ( dataset.supportsTransactions() ) {
dataset.begin( ReadWrite.READ );
}
// Get model inside the transaction
Model model = dataset.getDefaultModel();
StmtIterator si = model.listStatements();
try {
rc.begin();
while ( si.hasNext() ) {
Statement stmt = si.next();
com.hp.hpl.jena.rdf.model.Resource rsr = stmt.getSubject();
Property pred = stmt.getPredicate();
RDFNode val = stmt.getObject();
Node valnode = val.asNode();
Resource sub;
try {
sub = ( rsr.isAnon()
? vf.createBNode( valnode.getBlankNodeLabel() )
: vf.createURI( rsr.toString() ) );
}
catch ( UnsupportedOperationException uoo ) {
log.warn( uoo, uoo );
continue;
}
URI pred2 = vf.createURI( pred.toString() );
Value val2;
if ( val.isLiteral() ) {
Literal lit = val.asLiteral();
String dtstr = lit.getDatatypeURI();
URI dt = ( null == dtstr ? null : vf.createURI( dtstr ) );
String langstr = lit.getLanguage();
if ( null == dt ) {
if ( langstr.isEmpty() ) {
val2 = vf.createLiteral( lit.toString() );
}
else {
val2 = vf.createLiteral( lit.toString(), langstr );
}
}
else {
val2 = vf.createLiteral( lit.toString(), dt );
}
}
else {
if ( val.isAnon() ) {
val2 = vf.createBNode( valnode.getBlankNodeLabel() );
}
else {
val2 = vf.createURI( val.toString() );
}
}
rc.add( sub, pred2, val2 );
}
rc.commit();
}
catch ( RepositoryException re ) {
rc.rollback();
throw re;
}
finally {
if ( dataset.supportsTransactions() ) {
dataset.end();
}
}
}