本文整理汇总了Java中com.hp.hpl.jena.rdf.model.Literal类的典型用法代码示例。如果您正苦于以下问题:Java Literal类的具体用法?Java Literal怎么用?Java Literal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Literal类属于com.hp.hpl.jena.rdf.model包,在下文中一共展示了Literal类的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: asJenaLiteral
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
* Convert a Sesame Literal to a Jena Literal
* @param theLiteral the Sesame literal
* @return the sesame literal converted to Jena
*/
public static com.hp.hpl.jena.rdf.model.Literal asJenaLiteral(org.openrdf.model.Literal theLiteral) {
if (theLiteral == null) {
return null;
}
else if (theLiteral.getLanguage() != null) {
return mInternalModel.createLiteral(theLiteral.getLabel(),
theLiteral.getLanguage());
}
else if (theLiteral.getDatatype() != null) {
return mInternalModel.createTypedLiteral(theLiteral.getLabel(),
theLiteral.getDatatype().toString());
}
else {
return mInternalModel.createLiteral(theLiteral.getLabel());
}
}
示例3: 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;
}
示例4: copyAllowedProperties
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
protected void copyAllowedProperties(Model readModel, Model model, Set<Resource> classes,
Set<Property> allowedProperties) {
StmtIterator stmtIterator = readModel.listStatements();
Statement s;
Literal label;
while (stmtIterator.hasNext()) {
s = stmtIterator.next();
if (classes.contains(s.getSubject()) && allowedProperties.contains(s.getPredicate())
&& (!s.getObject().isAnon())) {
if (s.getPredicate().equals(RDFS.label)) {
label = s.getObject().asLiteral();
if (label.getLanguage().equals("en")) {
model.add(s.getSubject(), RDFS.label,
model.createLiteral(label.getString().toLowerCase(), "en"));
}
} else {
model.add(s);
}
}
}
}
示例5: parseN3
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
private static void parseN3(GrabMappingsHandler handler, String infileurl) {
Model model = ModelFactory.createDefaultModel();
model.read(infileurl, "N3");
AResourceImpl sub = new AResourceImpl();
AResourceImpl pred = new AResourceImpl();
AResourceImpl objres = new AResourceImpl();
ALiteralImpl objlit = new ALiteralImpl();
StmtIterator it = model.listStatements();
while (it.hasNext()) {
Statement stmt = it.nextStatement();
RDFNode object = stmt.getObject();
sub.setResource(stmt.getSubject());
pred.setResource(stmt.getPredicate());
if (object instanceof Literal) {
objlit.setLiteral((Literal) object);
handler.statement(sub, pred, objlit);
} else {
objres.setResource((Resource) object);
handler.statement(sub, pred, objres);
}
}
}
示例6: 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);
}
示例7: 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);
}
}
示例8: binding
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的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) {
}
}
示例9: 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) {
}
}
示例10: getGeoLocation
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
* Gets and returns the geolocation of a POI
* @param resource
* @return
*/
private static Literal getGeoLocation(String resource){
Literal geoLocation;
String sparqlquery= "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> \n"
+ "select distinct ?geolocation where {"
+ "<"+resource+"> geo:geometry ?geolocation.}\n"
+ "LIMIT 1 ";
Query query = QueryFactory.create(sparqlquery);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = qexec.execSelect();
if (results.hasNext() ){
QuerySolution soln = results.nextSolution();
geoLocation = soln.getLiteral("geolocation");
qexec.close();
return geoLocation;
}
else {
qexec.close();
return null;
}
}
示例11: graphNodeToSadlNode
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
* Convert a Jena graph Node to a SADL model Node
* @param node
* @return
*/
protected Node graphNodeToSadlNode(com.hp.hpl.jena.graph.Node node) {
if (node instanceof Node_Variable) {
return new VariableNode(((Node_Variable)node).getName().substring(1));
}
else if (node instanceof Node_URI) {
return new NamedNode(((Node_URI)node).getURI());
}
else if (node instanceof Node_Literal){
com.ge.research.sadl.model.gp.Literal lit = new com.ge.research.sadl.model.gp.Literal();
lit.setValue(((Node_Literal)node).getLiteral().getValue());
return lit;
}
else {
return new NamedNode(node.toString());
}
}
示例12: getMappingPrefix
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
private synchronized String getMappingPrefix(String modelName) {
Resource publicUri = getMappingModel().createResource(modelName);
StmtIterator sitr = getMappingModel().listStatements(null,
publicUrlProp, publicUri);
if (sitr.hasNext()) {
Resource ontSpec = sitr.nextStatement().getSubject();
Statement stmt = ontSpec.getProperty(prefixProp);
if (stmt != null) {
RDFNode val = stmt.getObject();
if (val.isLiteral()) {
return ((Literal) val).getLexicalForm();
}
}
}
return null;
}
示例13: getTranslatorForReasoner
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
@Override
public ITranslator getTranslatorForReasoner(String reasonerName) throws ConfigurationException {
if (getConfigModel() != null) {
Resource subject = getConfigModel().getResource("http://com.ge.research.sadl.configuration#" + reasonerName);
if (subject != null) {
Property predicate = getConfigModel().getProperty("http://com.ge.research.sadl.configuration#translatorClassName");
if (predicate != null) {
StmtIterator sitr = getConfigModel().listStatements(subject, predicate, (RDFNode)null);
if (sitr.hasNext()) {
RDFNode rcls = sitr.next().getObject();
if (rcls instanceof Literal) {
String clsName = rcls.asLiteral().getString();
return getTranslatorInstanceByClass(clsName);
}
}
}
}
}
return null;
}
示例14: getTranslatorClassName
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
* Method to return the fully qualified name of the class for the current ITranslator as specified in the configuration.
* @return
* @throws ConfigurationException
*/
public String getTranslatorClassName() throws ConfigurationException {
IReasoner reasonerInst = getReasonerInstance();
Resource reasonerCategory = getConfigModel().getResource(CONFIG_NAMESPACE + reasonerInst.getConfigurationCategory());
StmtIterator sitr = getConfigModel().listStatements(reasonerCategory,
getConfigModel().getProperty(pTRANSLATOR_CLASSNAME), (RDFNode)null);
if (sitr.hasNext()) {
RDFNode clsnmnode = sitr.nextStatement().getObject();
if (clsnmnode instanceof Literal) {
return ((Literal)clsnmnode).getValue().toString();
}
}
ITranslator translator = getTranslator();
if (translator != null) {
return translator.getClass().getCanonicalName();
}
throw new ConfigurationException("Unable to get current translator for unknown reason.");
}
示例15: getTranslatorInstance
import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
private ITranslator getTranslatorInstance() throws ConfigurationException {
String translatorClassName = null;
if (getConfigModel() != null) {
IReasoner reasonerInst = getReasonerInstance();
Resource reasonerCategory = getConfigModel().getResource(CONFIG_NAMESPACE + reasonerInst.getConfigurationCategory());
StmtIterator sitr = getConfigModel().listStatements(reasonerCategory,
getConfigModel().getProperty(pTRANSLATOR_CLASSNAME), (RDFNode)null);
if (sitr.hasNext()) {
RDFNode cnobj = sitr.next().getObject();
if (cnobj instanceof Literal) {
translatorClassName = ((Literal)cnobj).getLexicalForm();
}
}
}
if (translatorClassName == null) {
translatorClassName = DEFAULT_TRANSLATOR;
}
return getTranslatorInstanceByClass(translatorClassName);
}