@Override public boolean accept(Statement s) { RDFNode o = s.getObject(); if (o instanceof Literal) { if (l == null) return true; return (l.equals(((Literal) o).getLanguage())); } return false; } },
public String getLanguage() { return getLiteral().getLanguage(); }
private void addLiteralToElement( Element e, Literal L ) { String lang = L.getLanguage(); if (lang.length() > 0) e.setAttribute( "lang", lang ); String type = L.getDatatypeURI(); if (type != null) e.setAttribute( "datatype", shortNameFor( type ) ); e.appendChild( d.createTextNode( L.getLexicalForm() ) ); }
protected static void writeLiteral(Literal l, PrintWriter writer) { String s = l.getString(); /* if (l.getWellFormed()) writer.print("xml"); */ writer.print('"'); writeString(s, writer); writer.print('"'); String lang = l.getLanguage(); if (lang != null && !lang.equals("")) writer.print("@" + lang); String dt = l.getDatatypeURI(); if (dt != null && !dt.equals("")) writer.print("^^<" + dt + ">"); }
public Template(Literal literal, TermType termType, String namespace, Model model) { this.text = literal.getString(); this.language = literal.getLanguage(); this.fields = createTemplateFields(); this.termType = termType; this.namespace = namespace; this.model = model; }
@Override public boolean accept( Statement x ) { RDFNode o = x.getObject(); return o.isLiteral() && langTagMatch( m_lang, ((Literal) o).getLanguage() ); } }
protected void writeLiteral( Literal l, PrintWriter writer ) { String lang = l.getLanguage(); String form = l.getLexicalForm(); if (!lang.equals("")) { writer.print(" xml:lang=" + attributeQuoted( lang )); } if (l.isWellFormedXML() && !blockLiterals) { writer.print(" " + rdfAt("parseType") + "=" + attributeQuoted( "Literal" )+">"); writer.print( form ); } else { String dt = l.getDatatypeURI(); if (dt != null) writer.print( " " + rdfAt( "datatype" ) + "=" + substitutedAttribute( dt ) ); writer.print(">"); writer.print( Util.substituteEntitiesInElementContent( form ) ); } }
/** * Convert the given Jena Literal to a Sesame Literal * @param theLiteral the Jena Literal to convert * @return the Jena Literal as a Sesame Literal */ public static org.openrdf.model.Literal asSesameLiteral(Literal theLiteral) { if (theLiteral == null) { return null; } else if (theLiteral.getLanguage() != null && !theLiteral.getLanguage().equals("")) { return FACTORY.createLiteral(theLiteral.getLexicalForm(), theLiteral.getLanguage()); } else if (theLiteral.getDatatypeURI() != null) { return FACTORY.createLiteral(theLiteral.getLexicalForm(), FACTORY.createURI(theLiteral.getDatatypeURI())); } else { return FACTORY.createLiteral(theLiteral.getLexicalForm()); } }
/** Answer the String value of the literal <code>L</code>, which is the object of the Statement <code>s</code>. If the literal is not an XSD String or a plain string without a language code, throw a BadObjectException. */ public static String getString( Statement s, Literal L ) { if (!L.getLanguage().equals( "" )) throw new BadObjectException( s ); if (L.getDatatype() == null) return L.getLexicalForm(); if (L.getDatatype() == XSDDatatype.XSDstring) return L.getLexicalForm(); throw new BadObjectException( s ); }
private JsonObject literalAsJSON(Literal literal) { JsonObject jsonValue = new JsonObject() ; String datatype = literal.getDatatypeURI(); String lang = literal.getLanguage(); if (datatype != null && !datatype.equals("")) { jsonValue.put(dfType, dfTypedLiteral); jsonValue.put(dfDatatype, datatype) ; } else { jsonValue.put(dfType, dfLiteral) ; } if (lang != null && !(lang.length() == 0)) jsonValue.put(dfLang,lang); jsonValue.put(dfValue, literal.getLexicalForm()); return jsonValue ; } }
/** * <p>Answer true if this resource has the given label</p> * @param label The label to test for * @return True if this resource has <code>label</code> as a label. */ @Override public boolean hasLabel( Literal label ) { boolean found = false; ExtendedIterator<RDFNode> i = listLabels( label.getLanguage() ); while (!found && i.hasNext()) { found = label.equals( i.next() ); } i.close(); return found; }
public static String toSPARQL(Resource n){ if (n != null && (n.isResource() || n.isLiteral())){ if (n.isURIResource()) return "<" + n.getURI() + ">"; else if (n.isLiteral()) { String sparql = "'''" + sparqlEncode(n.asLiteral().toString()) + "'''"; //does it have a Datatype Literal? if (n.asLiteral().getDatatypeURI() != null){ sparql = sparql + "'''^^<" + n.asLiteral().getDatatypeURI().toString() + ">"; } if (n.asLiteral().getLanguage() != ""){ sparql = sparql + "'''@" + n.asLiteral().getLanguage(); } return sparql; } else return null; //TODO: throws exception } else return null; //TODO: throws exception }
/** * <p>Answer true if this resource has the given comment.</p> * @param comment The comment to test for * @return True if this resource has <code>comment</code> as a comment. */ @Override public boolean hasComment( Literal comment ) { boolean found = false; ExtendedIterator<RDFNode> i = listComments( comment.getLanguage() ); while (!found && i.hasNext()) { found = comment.equals( i.next() ); } i.close(); return found; }
void printLiteral(Literal literal) { String datatype = literal.getDatatypeURI() ; String lang = literal.getLanguage() ; out.print("<"+dfLiteral) ; if ( lang != null && !(lang.length()==0) ) out.print(" xml:lang=\""+lang+"\"") ; if ( datatype != null && ! datatype.equals("")) { // if ( datatype.startsWith(xsBaseURI) ) // { // String r = datatype.substring(xsBaseURI.length()) ; // out.print(" xsi:type=\"xsi:"+r+"\"") ; // } out.print(" "+dfAttrDatatype+"=\""+datatype+"\"") ; } out.print(">") ; out.print(xml_escape(literal.getLexicalForm())) ; out.println("</"+dfLiteral+">") ; }
/** Answer the plain string object of the statement <code>s</code>. If the object is not a string literal, throw a BadObjectException with that statement. */ public static String getString( Statement s ) { RDFNode ob = s.getObject(); if (ob.isResource()) throw new BadObjectException( s ); Literal L = (Literal) ob; if (!L.getLanguage().equals( "" )) throw new BadObjectException( s ); if (L.getDatatype() == null) return L.getLexicalForm(); if (L.getDatatype() == XSDDatatype.XSDstring) return L.getLexicalForm(); throw new BadObjectException( s ); }
private Value createValue(RDFNode object) { if(object.isLiteral()) { Literal literal = object.asLiteral(); return ProtocolFactory. newLiteral(). withLexicalForm(literal.getLexicalForm()). withDatatype(literal.getDatatypeURI()). withLanguage(literal.getLanguage()). build(); } else { return resolveResource(object.asResource(),true); } }
private boolean wPropertyEltValueString(WType wt, Property prop, Statement s, RDFNode r) { if (r instanceof Literal) { done(s); Literal lt = (Literal) r; String lang = lt.getLanguage(); tab(); print("<"); wt.wTypeStart(prop); wIdAttrReified(s); maybeNewline(); if (lang != null && lang.length() > 0) print(" xml:lang=" + q(lang)); maybeNewline(); print(">"); wValueString(lt); print("</"); wt.wTypeEnd(prop); print(">"); return true; } return false; }
private void populateBindingValue(BindingBuilder builder, RDFNode node) { LOGGER.trace("- Value {}",node); if(node.isLiteral()) { Literal literal=node.asLiteral(); builder. withValue( ProtocolFactory. newLiteral(). withLexicalForm(literal.getLexicalForm()). withDatatype(literal.getDatatypeURI()). withLanguage(literal.getLanguage())); } else if(node.isURIResource()) { builder.withValue(ProtocolFactory.newResource(node.asResource().getURI())); } else { builder.withValue(ProtocolFactory.newVariable(node.asResource().getId().getLabelString())); } }
private void printLiteral(Literal literal) { String datatype = literal.getDatatypeURI() ; String lang = literal.getLanguage() ; if ( datatype != null ) { out.print(quoteName(kDatatype)+": "+quote(datatype)+" , ") ; if ( multiLineValues ) out.println() ; out.print(quoteName(kType)+": "+quote(kTypedLiteral)+" , ") ; if ( multiLineValues ) out.println() ; } else { out.print(quoteName(kType)+": "+quote(kLiteral)+" , ") ; if ( multiLineValues ) out.println() ; if ( lang != null && !lang.equals("") ) { out.print(quoteName(kXmlLang)+": "+quote(lang)+" , ") ; if ( multiLineValues ) out.println() ; } } out.print(quoteName(kValue)+": "+quote(literal.getLexicalForm())) ; if ( multiLineValues ) out.println() ; }
private void printLiteral(Literal literal) { String datatype = literal.getDatatypeURI() ; String lang = literal.getLanguage() ; if ( datatype != null ) { out.print(quoteName(dfDatatype)+": "+quote(datatype)+" , ") ; if ( multiLineValues ) out.println() ; out.print(quoteName(dfType)+": "+quote(dfTypedLiteral)+" , ") ; if ( multiLineValues ) out.println() ; } else { out.print(quoteName(dfType)+": "+quote(dfLiteral)+" , ") ; if ( multiLineValues ) out.println() ; if ( lang != null && !lang.equals("") ) { out.print(quoteName(dfLang)+": "+quote(lang)+" , ") ; if ( multiLineValues ) out.println() ; } } out.print(quoteName(dfValue)+": "+quote(literal.getLexicalForm())) ; if ( multiLineValues ) out.println() ; }