本文整理汇总了Java中org.apache.jena.rdf.model.ResourceFactory.createTypedLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceFactory.createTypedLiteral方法的具体用法?Java ResourceFactory.createTypedLiteral怎么用?Java ResourceFactory.createTypedLiteral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.ResourceFactory
的用法示例。
在下文中一共展示了ResourceFactory.createTypedLiteral方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypedContent
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
public Literal getTypedContent(String con) {
try {
return ResourceFactory.createTypedLiteral(Double.valueOf(con));
// return "\"" + Double.valueOf(con) + "\"^^xsd:double";
} catch (java.lang.NumberFormatException e) {
try {
return ResourceFactory.createTypedLiteral(Float.valueOf(con));
// return "\"" + Float.valueOf(con) + "\"^^xsd:float";
} catch (Exception e2) {
return ResourceFactory.createTypedLiteral(String.valueOf(con));
// return "\"" + con + "\"^^xsd:string";
}
}
}
示例2: toRDFNode
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
public static RDFNode toRDFNode(String value) {
if (isURI(value)) {
return ResourceFactory.createResource(value);
} else if (NumberUtils.isNumber(value)) {
if (value.contains(".")) {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDdouble);
}
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDboolean);
} else {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDinteger);
}
} else {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring);
}
}
示例3: addProperties
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
public void addProperties(List<UDTValue> properties) {
if (properties != null && !properties.isEmpty()) {
for (UDTValue value : properties) {
Property property = ResourceFactory.createProperty(value.getString("property"));
RDFNode propertyValue;
if (value.isNull("datatype")) {
propertyValue = ResourceFactory.createResource(value.getString("value"));
} else {
propertyValue = ResourceFactory.createTypedLiteral(value.getString("value"),
TypeMapper.getInstance().getSafeTypeByName(value.getString("datatype")));
}
addProperty(property, propertyValue);
}
}
}
示例4: createTyped
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
public static final RDFNode createTyped(String value, Resource valueType)
{
if (value == null) throw new IllegalArgumentException("Param value cannot be null");
// without value type, return default xsd:string value
if (valueType == null) return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring);
// if value type is from XSD namespace, value is treated as typed literal with XSD datatype
if (valueType.getNameSpace().equals(XSD.getURI()))
{
RDFDatatype dataType = NodeFactory.getType(valueType.getURI());
return ResourceFactory.createTypedLiteral(value, dataType);
}
// otherwise, value is treated as URI resource
else
return ResourceFactory.createResource(value);
}
示例5: main
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
public static void main(String args[]){
InstanceSplitModifier sM=new InstanceSplitModifier();
Resource s = ResourceFactory.createResource("medo.test");
RDFNode o= ResourceFactory.createTypedLiteral("Medo koko dodo");
Statement stmt = ResourceFactory.createStatement(s, RDFS.label, o);
sM.setPartsCount(3);
List<Property> sP = new ArrayList<Property>();
// sP.add(ResourceFactory.createProperty("Name1"));
// sP.add(ResourceFactory.createProperty("Name2"));
// sP.add(ResourceFactory.createProperty("Name3"));
sM.setSplitProperties(sP);
System.out.println(sP);
System.out.println(sM.split(stmt));
System.out.println(o);
System.out.println(o.asNode().getLiteral().getLexicalForm());
}
示例6: l
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
private static Literal l(Object value) {
if (value != null) {
return ResourceFactory.createTypedLiteral(value);
} else {
return ResourceFactory.createTypedLiteral("");
}
}
示例7: addParameters
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
public void addParameters(List<UDTValue> parameters) {
if (parameters != null && !parameters.isEmpty()) {
for (UDTValue value : parameters) {
Resource parameter = ResourceFactory.createResource(value.getString("for_parameter"));
RDFNode parameterValue = ResourceFactory.createTypedLiteral(value.getString("value"),
TypeMapper.getInstance().getSafeTypeByName(value.getString("datatype")));
addParameter(parameter, parameterValue);
}
}
}
示例8: toLiteral
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
private Literal toLiteral(Object value) {
if (value instanceof String) {
return ResourceFactory.createPlainLiteral(value.toString());
}
if (value instanceof Double) {
return ResourceFactory.createTypedLiteral(value.toString(), XSDDatatype.XSDdouble);
}
throw new IllegalArgumentException();
}
示例9: toLiteral
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
public static Literal toLiteral(Object value) {
if (value instanceof String) {
return ResourceFactory.createPlainLiteral(value.toString());
}
if (value instanceof Double) {
return ResourceFactory.createTypedLiteral(value.toString(),
XSDDatatype.XSDdouble);
}
throw new IllegalArgumentException();
}
示例10: withSubstitutions
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
public static Literal withSubstitutions(Literal template, QuerySolution bindings, Function<RDFNode,String> labelFunction) {
StringBuffer buffer = new StringBuffer();
String labelTemplate = template.getLexicalForm();
for(int i = 0; i < labelTemplate.length(); i++) {
if(i < labelTemplate.length() - 3 && labelTemplate.charAt(i) == '{' && (labelTemplate.charAt(i + 1) == '?' || labelTemplate.charAt(i + 1) == '$')) {
int varEnd = i + 2;
while(varEnd < labelTemplate.length()) {
if(labelTemplate.charAt(varEnd) == '}') {
String varName = labelTemplate.substring(i + 2, varEnd);
RDFNode varValue = bindings.get(varName);
if(varValue != null) {
if(labelFunction != null) {
buffer.append(labelFunction.apply(varValue));
}
else if(varValue instanceof Resource) {
buffer.append(RDFLabels.get().getLabel((Resource)varValue));
}
else if(varValue instanceof Literal) {
buffer.append(varValue.asNode().getLiteralLexicalForm());
}
}
break;
}
else {
varEnd++;
}
}
i = varEnd;
}
else {
buffer.append(labelTemplate.charAt(i));
}
}
if(template.getLanguage().isEmpty()) {
return ResourceFactory.createTypedLiteral(buffer.toString());
}
else {
return ResourceFactory.createLangLiteral(buffer.toString(), template.getLanguage());
}
}
示例11: createTypedLiteral
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
/**
*
* @param label
* @param typeURI
* @return
*/
@Override
public RDFNode createTypedLiteral( final String label,
final String typeURI )
{
final RDFDatatype dt = TypeMapper.getInstance()
.getSafeTypeByName( typeURI );
return ResourceFactory.createTypedLiteral( label, dt );
}
示例12: permutat
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
private Statement permutat(Statement stmt) {
if (!stmt.getObject().isLiteral()) {
// System.err.println(stmt.getObject() + " is not a literal object");
// System.err.println("Can NOT permutate a non-literal object!!");
// System.exit(1);
return stmt;
}
String objectLitral = stmt.getObject().asNode().getLiteral().getLexicalForm();
String permutatedLitral = permutat(objectLitral);
RDFNode permutatedObject = ResourceFactory.createTypedLiteral(permutatedLitral);
Statement result = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), permutatedObject);
return result;
}
示例13: abbreviat
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
private Statement abbreviat(Statement stmt) {
if (!stmt.getObject().isLiteral()) {
// System.err.println(stmt.getObject() + " is not a literal object");
// System.err.println("Unable to abbreviat a non-literal object!!");
// System.exit(1);
return stmt;
}
String objectLitral = stmt.getObject().asNode().getLiteral().getLexicalForm();
String abbreviatedLitral = abbreviat(objectLitral);
RDFNode abbreviatedObject = ResourceFactory.createTypedLiteral(abbreviatedLitral);
Statement result = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), abbreviatedObject);
return result;
}
示例14: split
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
private List<Statement> split(Statement stmt){
List<Statement> result= new ArrayList<Statement>();
if(!stmt.getObject().isLiteral()){
System.err.println(stmt.getObject() + " is not a literal object");
System.err.println("Can NOT split a non-literal object!!");
// System.exit(1);
result.add(stmt);
return result;
}
Resource subject = stmt.getSubject();
Property predicate = stmt.getPredicate();
RDFNode object = stmt.getObject();
String[] splitObject = object.toString().split(" ", partsCount);
for(int i=0; i<splitObject.length ; i++){
RDFNode newObject= ResourceFactory.createTypedLiteral(splitObject[i]);
Statement resultStmt;
// if no user defined new properties then create the new properties as the old property name + "i"
if(splitProperties.isEmpty()){
Property newPredicate = ResourceFactory.createProperty(predicate.toString()+i);
resultStmt = ResourceFactory.createStatement(subject, newPredicate, newObject);
}else{
resultStmt = ResourceFactory.createStatement(subject, splitProperties.get(i), newObject);
}
result.add(resultStmt);
}
return result;
}
示例15: acronyam
import org.apache.jena.rdf.model.ResourceFactory; //导入方法依赖的package包/类
private Statement acronyam(Statement stmt){
if(!stmt.getObject().isLiteral()){
System.err.println(stmt.getObject() + " is not a literal object");
System.err.println("Can NOT get acronyam for non-literal object!!");
// System.exit(1);
return stmt;
}
String objectLitral = stmt.getObject().asNode().getLiteral().getLexicalForm();
String acronyamedLitral = acronyam(objectLitral);
RDFNode acronyamedObject= ResourceFactory.createTypedLiteral(acronyamedLitral);
Statement result = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), acronyamedObject);
return result;
}