本文整理匯總了Java中com.hp.hpl.jena.rdf.model.Literal.getLanguage方法的典型用法代碼示例。如果您正苦於以下問題:Java Literal.getLanguage方法的具體用法?Java Literal.getLanguage怎麽用?Java Literal.getLanguage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.rdf.model.Literal
的用法示例。
在下文中一共展示了Literal.getLanguage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: asSesameLiteral
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
/**
* 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());
}
}
示例2: getSubclass
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
public OntoRecord getSubclass(String resourceURI, String lang){
StmtIterator iter1 = model.listStatements( new SimpleSelector(ResourceFactory.createResource(resourceURI), ResourceFactory.createProperty("http://www.w3.org/2000/01/rdf-schema#subClassOf"), (RDFNode)null));
OntoRecord record = new OntoRecord();
StmtIterator iter2;
while(iter1.hasNext()) {
record.setUri(iter1.next().getObject().toString());
iter2 = model.listStatements( new SimpleSelector(ResourceFactory.createResource(record.getUri()), ResourceFactory.createProperty("http://www.w3.org/2000/01/rdf-schema#label"), (RDFNode)null));
while(iter2.hasNext()){
Literal res = (Literal) iter2.next().getObject();
String tmpLang = res.getLanguage();
if( tmpLang.equals("en") ){
record.setLabel(res.getString());
return record;
}
}
}
return null;
}
示例3: writeStatement
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的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);
}
示例4: fixLanguage
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的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);
}
}
示例5: literal
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
private void literal(Literal l) {
atts.clear();
try {
String s = l.getLexicalForm();
String lang = l.getLanguage();
String dt = l.getDatatypeURI();
// Literal with lang?
if (lang != null && lang.length() != 0) {
atts.addAttribute(ARQConstants.XML_NS, "lang", "xml:lang", "CDATA", lang);
}
// Literal with datatype?
if (dt != null && dt.length() != 0) {
atts.addAttribute(dfNamespace, dfAttrDatatype, dfAttrDatatype, "CDATA", dt);
}
handler.startElement(dfNamespace, dfLiteral, dfLiteral, atts);
handler.characters(s.toCharArray(), 0, s.length());
handler.endElement(dfNamespace, dfLiteral, dfLiteral);
} catch (SAXException ex) {
}
}
示例6: writeLiteral
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
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 ) );
}
}
示例7: asSesameLiteral
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
/**
* 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());
}
}
示例8: compute
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
@Override
public void compute(Quad quad) {
Node obj = quad.getObject();
if (obj.isLiteral()){
RDFNode n = Commons.asRDFNode(obj);
Literal lt = (Literal) n;
String language = lt.getLanguage();
if (!language.equals("")){
totalvalidLangStrings++;
try {
if (this.correctLanguageTag(obj)) totalCorrectStrings++;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
示例9: indexAnnotation
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
private void indexAnnotation(Resource skos_concept, Document conceptDoc,
AnnotationProperty property, String field) {
StmtIterator stmt_iter = skos_concept.listProperties(property);
while (stmt_iter.hasNext()) {
Literal labelLiteral = stmt_iter.nextStatement().getObject()
.as(Literal.class);
String label = labelLiteral.getLexicalForm();
String labelLang = labelLiteral.getLanguage();
if (this.languages != null && !this.languages.contains(labelLang)) {
continue;
}
// converting label to lower-case
label = label.toLowerCase();
Field labelField = new Field(field, label, StringField.TYPE_STORED);
conceptDoc.add(labelField);
}
}
示例10: object
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的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>";
}
}
示例11: checkLiteral
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
private boolean checkLiteral(Literal l)
{
String lang = l.getLanguage();
if ( ignore.contains(lang) ) { return false; }
String str = YorgosUtils.cleanExcess(l.getString());
return ( str.split(" ").length <= 1);
}
示例12: getLanguage
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
public static String getLanguage(String key, QuerySolution querySolution) {
if (key == null) {
return null;
}
Literal literal = querySolution.getLiteral(key);
return literal != null ? literal.getLanguage() : null;
}
示例13: processProperty
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
private void processProperty(Statement property) throws IOException {
write("{ \"value\" : \"");
if (property.getObject().isURIResource()) {
Resource r = (Resource) property.getObject();
write(escape(r.getURI()));
write("\", \"type\" : \"uri\"");
} else if (property.getObject().isLiteral()) {
Literal l = (Literal) property.getObject();
write(escape(l.getLexicalForm()));
write("\", \"type\" : \"literal\"");
String languageValue = l.getLanguage();
if (languageValue != null && !languageValue.trim().equals("")) {
write(", \"lang\" : \"");
write(languageValue);
write("\"");
}
String dataTypeValue = l.getDatatypeURI();
if (dataTypeValue != null && !dataTypeValue.trim().equals("")) {
write(", \"datatype\" : \"");
write(escape(dataTypeValue));
write("\"");
}
} else if (property.getObject().isAnon()) {
write("_:");
write(escape(property.getObject().asNode().getBlankNodeId()
.getLabelString()));
write("\", \"type\" : \"bnode\"");
}
write(" }");
}
示例14: getServiceTypes
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的package包/類
/**
* Retreives existing types of services in the ldi-schema ontology
*
* @return Collection<ServiceType> collection with the existing services uris and labels
* @throws IOException
*/
public Collection<ServiceType> getServiceTypes() throws IOException {
if (serviceTypes == null) {
Map<String, ServiceType> services = new HashMap<String, ServiceType>();
// read the ontology file and get the list
String query =
"SELECT ?uri ?label {?uri <" + RDFS.subClassOf.getURI() + "> <"
+ LDIS.ComponentService.getURI() + "> ; <" + RDFS.label.getURI() + "> ?label}";
log.debug(query);
QueryExecution qexec = QueryExecutionFactory.create(query, LDIS.getModel());
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution soln = results.next();
String uri = soln.get("uri").asResource().getURI();
Literal literal = soln.get("label").asLiteral();
String language = literal.getLanguage();
if (literal.getLanguage().equals(""))
language = "default";
ServiceType st = null;
if (services.containsKey(uri))
st = services.get(uri);
else {
st = new ServiceType();
st.setUri(uri);
services.put(uri, st);
}
st.getLabels().put(language, literal.getString());
}
serviceTypes = services.values();
}
return serviceTypes;
}
示例15: copyFromTdb
import com.hp.hpl.jena.rdf.model.Literal; //導入方法依賴的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();
}
}
}