• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TypeMapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.jena.datatypes.TypeMapper的典型用法代码示例。如果您正苦于以下问题:Java TypeMapper类的具体用法?Java TypeMapper怎么用?Java TypeMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TypeMapper类属于org.apache.jena.datatypes包,在下文中一共展示了TypeMapper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: addProperties

import org.apache.jena.datatypes.TypeMapper; //导入依赖的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);
    }
  }
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:17,代码来源:CommandResult.java


示例2: exec

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@Override
protected NodeValue exec(Node literalNode, Node datatypeNode, FunctionEnv env) {
	
	if(literalNode == null || !literalNode.isLiteral()) {
		throw new ExprEvalException();
	}
	String lex = literalNode.getLiteralLexicalForm();
	
	if(!datatypeNode.isURI()) {
		throw new ExprEvalException();
	}
	RDFDatatype datatype = TypeMapper.getInstance().getTypeByName(datatypeNode.getURI());
	
	if(datatype == null) {
		return NodeValue.TRUE;
	}
	else {
		boolean valid = datatype.isValid(lex);
		return NodeValue.makeBoolean(valid);
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:22,代码来源:IsValidForDatatypeFunction.java


示例3: build

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
public org.apache.jena.graph.Node build() {
    if (dt != null) {
        RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(dt);
        return NodeFactory.createLiteral(value, dType);
    } else if (lang != null && !lang.isEmpty())
        return NodeFactory.createLiteral(value, lang);
    else
        return NodeFactory.createLiteral(value);
}
 
开发者ID:IBCNServices,项目名称:OBEP,代码行数:10,代码来源:RDFLiteral.java


示例4: exec

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue cbor, NodeValue jsonpath) {
    if (cbor.getDatatypeURI() != null
            && !cbor.getDatatypeURI().equals(datatypeUri)
            && !cbor.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
        LOG.warn("The URI of NodeValue1 MUST be"
                + " <" + datatypeUri + "> or"
                + " <http://www.w3.org/2001/XMLSchema#string>. Got <"
                + cbor.getDatatypeURI() + ">. Returning null.");
    }

    Configuration conf = Configuration.builder()
            .options(Option.ALWAYS_RETURN_LIST).build();

    String json = new String(Base64.getDecoder().decode(cbor.asNode().getLiteralLexicalForm().getBytes()));

    try {
        List<Object> values = JsonPath
                .using(conf)
                .parse(json)
                .read(jsonpath.getString());
        List<NodeValue> nodeValues = new ArrayList<>(values.size());
        Gson gson = new Gson();
        for (Object value : values) {
            RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(datatypeUri);
            String jsonstring = gson.toJson(value);
            Node node = NodeFactory.createLiteral(jsonstring, dt);
            NodeValue nodeValue = new NodeValueNode(node);
            nodeValues.add(nodeValue);
        }
        return nodeValues;
    } catch (Exception ex) {
        LOG.debug("No evaluation of " + cbor + ", " + jsonpath, ex);
        throw new ExprEvalException("No evaluation of " + cbor + ", " + jsonpath, ex);
    }
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:37,代码来源:ITER_CBOR.java


示例5: exec

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue json, NodeValue jsonquery) {
    if (json.getDatatypeURI() != null
            && !json.getDatatypeURI().equals(datatypeUri)
            && !json.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
        LOG.warn("The URI of NodeValue1 MUST be"
                + " <" + datatypeUri + "> or"
                + " <http://www.w3.org/2001/XMLSchema#string>. Got "
                + json.getDatatypeURI());
    }
    Configuration conf = Configuration.builder()
            .options(Option.ALWAYS_RETURN_LIST).build();

    try {
        List<Object> values = JsonPath
                .using(conf)
                .parse(json.asNode().getLiteralLexicalForm())
                .read(jsonquery.getString());
        List<NodeValue> nodeValues = new ArrayList<>(values.size());
        Gson gson = new Gson();
        for (Object value : values) {
            RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(datatypeUri);
            String jsonstring = gson.toJson(value);
            Node node = NodeFactory.createLiteral(jsonstring, dt);
            NodeValue nodeValue = new NodeValueNode(node);
            nodeValues.add(nodeValue);
        }
        return nodeValues;
    } catch (Exception ex) {
        LOG.debug("No evaluation for " + json + ", " + jsonquery, ex);
        throw new ExprEvalException("No evaluation for " + json + ", " + jsonquery, ex);
    }
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:34,代码来源:ITER_JSONPath.java


示例6: exec

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue html, NodeValue cssSelector) {
    if (html.getDatatypeURI() != null
            && !html.getDatatypeURI().equals(datatypeUri)
            && !html.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
        LOG.warn("The URI of NodeValue1 MUST be"
                + " <" + datatypeUri + "> or"
                + " <http://www.w3.org/2001/XMLSchema#string>. Got <"
                + html.getDatatypeURI() + ">. Returning null.");
    }
    RDFDatatype dt = TypeMapper.getInstance()
            .getSafeTypeByName(datatypeUri);
    try {

        String sourceHtml = String.valueOf(html.asNode().getLiteralLexicalForm());
        Document htmldoc = Jsoup.parse(sourceHtml);

        String selectPath = String.valueOf(cssSelector.asNode().getLiteralValue());
        Elements elements = htmldoc.select(selectPath);

        LOG.debug("===> Number of iterations for " + cssSelector + " " + elements.size());

        List<NodeValue> nodeValues = new ArrayList<>(elements.size());

        NodeValue nodeValue;
        for (Element element : elements) {
            String htmlValue = element.toString();
            Node node = NodeFactory.createLiteral(htmlValue, dt);
            nodeValue = new NodeValueNode(node);

            nodeValues.add(nodeValue);
        }

        return nodeValues;
    } catch (Exception ex) {
        LOG.debug("No evaluation of " + html + ", " + cssSelector, ex);
        throw new ExprEvalException("No evaluation of " + html + ", " + cssSelector, ex);
    }
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:40,代码来源:ITER_CSSPath.java


示例7: addParameters

import org.apache.jena.datatypes.TypeMapper; //导入依赖的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);
    }
  }
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:12,代码来源:CommandResult.java


示例8: literal

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
public JSLiteral literal(String value, Object langOrDatatype) {
	if(langOrDatatype instanceof JSNamedNode) {
		return new JSLiteral(NodeFactory.createLiteral(value, TypeMapper.getInstance().getTypeByName(((JSNamedNode)langOrDatatype).getValue())));
	}
	else if(langOrDatatype instanceof String) {
		return new JSLiteral(NodeFactory.createLiteral(value, (String)langOrDatatype));
	}
	else {
		throw new IllegalArgumentException("Invalid type of langOrDatatype argument");
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:12,代码来源:TermFactory.java


示例9: getNode

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static Node getNode(Object obj) {
	if(obj == null) {
		return null;
	}
	else if(obj instanceof JSTerm) {
		return ((JSTerm)obj).getNode();
	}
	else if(obj instanceof Map) {
		Map som = (Map) obj;
		String value = (String) som.get(VALUE);
		if(value == null) {
			throw new IllegalArgumentException("Missing value");
		}
		String termType = (String) som.get(TERM_TYPE);
		if(NAMED_NODE.equals(termType)) {
			return NodeFactory.createURI(value);
		}
		else if(BLANK_NODE.equals(termType)) {
			return NodeFactory.createBlankNode(value);
		}
		else if(LITERAL.equals(termType)) {
			String lang = (String) som.get(LANGUAGE);
			Map dt = (Map)som.get(DATATYPE);
			String dtURI = (String)dt.get(VALUE);
			RDFDatatype datatype = TypeMapper.getInstance().getSafeTypeByName(dtURI);
			return NodeFactory.createLiteral(value, lang, datatype);
		}
		else {
			throw new IllegalArgumentException("Unsupported term type " + termType);
		}
	}
	else {
		return null;
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:37,代码来源:JSFactory.java


示例10: addNamespace

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
public static Resource addNamespace(Resource ontology, String prefix, String namespace) {
	Resource declaration = ontology.getModel().createResource(SH.PrefixDeclaration);
	ontology.addProperty(SH.declare, declaration);
	declaration.addProperty(SH.prefix, prefix);
	declaration.addProperty(SH.namespace, ResourceFactory.createTypedLiteral(namespace, TypeMapper.getInstance().getSafeTypeByName(XSD.anyURI.getURI())));
	return declaration;
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:8,代码来源:PrefixUtil.java


示例11: bodyCall

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
public boolean bodyCall(Node[] args, int length, RuleContext context) {
	BindingEnvironment env = context.getEnv();
	Node value = env.getGroundVersion(args[0]);
	TypeMapper tm = TypeMapper.getInstance();
	RDFDatatype type = tm.getTypeByName(PrintUtil.expandQname(args[2].toString()));
	Node cast = NodeFactory.createLiteral(value.getLiteral().getValue().toString(),null,type);
	env.bind(args[1],cast);
	return type.isValid(value.getLiteral().getValue().toString());
}
 
开发者ID:stevebattle,项目名称:Gloze,代码行数:10,代码来源:Cast.java


示例12: bodyCall

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
public boolean bodyCall(Node[] args, int length, RuleContext context) {
	BindingEnvironment env = context.getEnv();
	InfGraph graph = context.getGraph();

	Node s = env.getGroundVersion(args[0]);
	Node p = env.getGroundVersion(args[1]);
	ExtendedIterator i = graph.find(s,p,null);
	int n = i.toSet().size();
	
	TypeMapper tm = TypeMapper.getInstance();
	RDFDatatype type = tm.getTypeByName(XSD.xint.getURI());
	Node count = NodeFactory.createLiteral(Integer.toString(n),null,type);
	env.bind(args[2],count);
	return true;
}
 
开发者ID:stevebattle,项目名称:Gloze,代码行数:16,代码来源:CountValues.java


示例13: createTypedLiteral

import org.apache.jena.datatypes.TypeMapper; //导入依赖的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 );
}
 
开发者ID:LinkedDataFragments,项目名称:Server.Java,代码行数:15,代码来源:TriplePatternElementParserForJena.java


示例14: datatype

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
public static Node datatype(Object value, Object type) {
    String typeURI = type.toString();
    if (typeURI.startsWith("xsd:")) {
        typeURI = typeURI.replace("xsd:", XSD.getURI());
    }
    RDFDatatype typeR = TypeMapper.getInstance().getSafeTypeByName( typeURI );
    return NodeFactory.createLiteral(value.toString(), typeR);
}
 
开发者ID:epimorphics,项目名称:dclib,代码行数:9,代码来源:GlobalFunctions.java


示例15: fromDateTime

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
protected static Value fromDateTime(DateTime time, String typeURI, boolean withTZ) {
    String formatted;
    if (typeURI.equals(XSD.dateTime.getURI())) {
        if (time.getMillisOfSecond() == 0) {
            formatted = (withTZ ? DATETIME_TZ_FMT : DATETIME_FMT).print(time);
        } else {
            formatted = (withTZ ? DATETIME_TZ_FMT_MS : DATETIME_FMT_MS).print(time);
        }
    } else if (typeURI.equals(XSD.date.getURI())) {
        formatted = (withTZ ? DATE_TZ_FMT : DATE_FMT).print(time);
    } else if (typeURI.equals(XSD.time.getURI())) {
        if (time.getMillisOfSecond() == 0) {
            formatted = (withTZ ? TIME_TZ_FMT : TIME_FMT).print(time);
        } else {
            formatted = (withTZ ? TIME_TZ_FMT_MS : TIME_FMT_MS).print(time);
        }
    } else if (typeURI.equals(XSD.gYearMonth.getURI())) {
        formatted = GYEARMONTH_FMT.print(time);
    } else if (typeURI.equals(XSD.gYear.getURI())) {
        formatted = GYEAR_FMT.print(time);
    } else {
        throw new EpiException("Unrecognized datetime type");
    }
    if (formatted.endsWith("UTC")) {
        formatted = formatted.replace("UTC", "Z");
    }
    Node n = NodeFactory.createLiteral(formatted, TypeMapper.getInstance().getSafeTypeByName(typeURI));
    return new ValueDate(n);        
}
 
开发者ID:epimorphics,项目名称:dclib,代码行数:30,代码来源:ValueDate.java


示例16: asNode

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@Override
public Node asNode() {
    int split = value.lastIndexOf("@");
    if (split != -1 && (value.length() - split < MAX_LANGSTR) && split != 0) {
        String possLangTag = value.substring(split);
        Matcher matcher = LANGSTR.matcher(possLangTag);
        if (matcher.find()) {
            String lang = matcher.group(1);
            if (value.charAt(split-1) == '@') {
                return NodeFactory.createLiteral( value.substring(0, split) + lang );
            } else if (value.charAt(split-1) == '\\') {
                return NodeFactory.createLiteral( value.substring(0, split-1) + "@" + lang );
            } else {
                return NodeFactory.createLiteral(value.substring(0, split), lang, false);
            }
        }
    }
    
    // Check for typed literal
    split = value.lastIndexOf("^^");
    if (split != -1) {
        if (value.charAt(split-1) != '\\') {
            String lex = value.substring(0, split);
            String dt = value.substring(split+2);
            if (dt.startsWith("<") && dt.endsWith(">")) {
                dt = dt.substring(1, dt.length() - 1);
            }
            dt = ConverterProcess.getGlobalDataContext().expandURI(dt);
            return NodeFactory.createLiteral(lex, TypeMapper.getInstance().getSafeTypeByName(dt));
        } else {
            return NodeFactory.createLiteral(value.substring(0,split-1) + value.substring(split));
        }
    }

    return NodeFactory.createLiteral( value );
}
 
开发者ID:epimorphics,项目名称:dclib,代码行数:37,代码来源:ValueString.java


示例17: getSafeTypeByName

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
public RDFDatatype getSafeTypeByName(String uri) {
    RDFDatatype safeTypeByName = TypeMapper.getInstance().getSafeTypeByName(uri);
    return safeTypeByName;
}
 
开发者ID:IBCNServices,项目名称:OBEP,代码行数:5,代码来源:ParserUtils.java


示例18: exec

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@Override
public NodeValue exec(NodeValue xml, NodeValue xpath) {
    if (xml.getDatatypeURI() != null
            && !xml.getDatatypeURI().equals(datatypeUri)
            && !xml.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
        LOG.warn("The URI of NodeValue1 MUST be <" + datatypeUri + ">"
                + " or <http://www.w3.org/2001/XMLSchema#string>. Got "
                + xml.getDatatypeURI());
    }
    DocumentBuilderFactory builderFactory
            = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);
    DocumentBuilder builder = null;
    try {
        // THIS IS A HACK !! FIND A BETTER WAY TO MANAGE NAMESPACES
        String xmlstring = xml.asNode().getLiteralLexicalForm().replaceAll("xmlns=\"[^\"]*\"", "");

        builder = builderFactory.newDocumentBuilder();
        InputStream in = new ByteArrayInputStream(xmlstring.getBytes("UTF-8"));
        Document document = builder.parse(in);

        XPath xPath = XPathFactory.newInstance().newXPath();
        xPath.setNamespaceContext(new UniversalNamespaceResolver(document));
        //Node node = (Node) xPath.compile(xpath.getString()).evaluate(document, XPathConstants.NODE);

        org.w3c.dom.Node xmlNode = (org.w3c.dom.Node) xPath
                .compile(xpath.getString())
                .evaluate(document, XPathConstants.NODE);
        if (xmlNode == null) {
            LOG.debug("No evaluation of " + xpath);
            throw new ExprEvalException("No evaluation of " + xpath);
        }

        /*
            Node node = NodeFactory.createLiteral(xmlNode.getNodeValue(), dt);
            NodeValue nodeValue = new NodeValueNode(node);
            nodeValues.add(nodeValue);
         */
        NodeValue nodeValue = null;
        Object value = xmlNode.getNodeValue();
        if (value instanceof Float) {
            nodeValue = new NodeValueFloat((Float) value);
        } else if (value instanceof Boolean) {
            nodeValue = new NodeValueBoolean((Boolean) value);
        } else if (value instanceof Integer) {
            nodeValue = new NodeValueInteger((Integer) value);
        } else if (value instanceof Double) {
            nodeValue = new NodeValueDouble((Double) value);
        } else if (value instanceof BigDecimal) {
            nodeValue = new NodeValueDecimal((BigDecimal) value);
        } else if (value instanceof String) {
            nodeValue = new NodeValueString((String) value);
        } else {

            RDFDatatype dt = TypeMapper.getInstance()
                    .getSafeTypeByName(datatypeUri);

            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            DOMSource source = new DOMSource(xmlNode);
            StringWriter writer = new StringWriter();
            transformer.transform(source, new StreamResult(writer));
            Node node = NodeFactory.createLiteral(writer.getBuffer().toString(), dt);
            nodeValue = new NodeValueNode(node);
        }
        LOG.debug("Evaluation of " + xpath + ":  " + nodeValue);
        return nodeValue;
    } catch (Exception ex) {
        LOG.debug("No evaluation of " + xml + ", " + xpath, ex);
        throw new ExprEvalException("No evaluation of " + xml + ", " + xpath, ex);
    }
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:73,代码来源:FUN_XPath.java


示例19: exec

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue xml, NodeValue v2) {
    if (xml.getDatatypeURI() != null
            && !xml.getDatatypeURI().equals(datatypeUri)
            && !xml.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
        LOG.warn("The URI of NodeValue1 MUST be"
                + " <" + datatypeUri + "> "
                + " or <http://www.w3.org/2001/XMLSchema#string>. Got "
                + xml.getDatatypeURI());
    }
    DocumentBuilderFactory builderFactory
            = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);
    DocumentBuilder builder = null;
    try {
        // THIS IS A HACK !! FIND A BETTER WAY TO MANAGE NAMESPACES
        String xmlstring = xml.asNode().getLiteralLexicalForm().replaceAll("xmlns=\"[^\"]*\"", "");

        builder = builderFactory.newDocumentBuilder();
        Document document = builder
                .parse(new ByteArrayInputStream(xmlstring.getBytes("UTF-8")));

        XPath xPath = XPathFactory.newInstance().newXPath();

        NodeList nodeList = (NodeList) xPath
                .compile(v2.getString())
                .evaluate(document, XPathConstants.NODESET);

        //will contain the final results
        List<NodeValue> nodeValues = new ArrayList<>(nodeList.getLength());

        for (int i = 0; i < nodeList.getLength(); i++) {

            org.w3c.dom.Node xmlNode = nodeList.item(i);

            RDFDatatype dt = TypeMapper.getInstance()
                    .getSafeTypeByName(datatypeUri);
            /*
            Node node = NodeFactory.createLiteral(xmlNode.getNodeValue(), dt);
            NodeValue nodeValue = new NodeValueNode(node);
            nodeValues.add(nodeValue);
             */
            NodeValue nodeValue = null;
            Object value = xmlNode.getNodeValue();
            if (value instanceof Float) {
                nodeValue = new NodeValueFloat((Float) value);
            } else if (value instanceof Boolean) {
                nodeValue = new NodeValueBoolean((Boolean) value);
            } else if (value instanceof Integer) {
                nodeValue = new NodeValueInteger((Integer) value);
            } else if (value instanceof Double) {
                nodeValue = new NodeValueDouble((Double) value);
            } else if (value instanceof BigDecimal) {
                nodeValue = new NodeValueDecimal((BigDecimal) value);
            } else if (value instanceof String) {
                nodeValue = new NodeValueString((String) value);
            } else {

                TransformerFactory tFactory = TransformerFactory.newInstance();
                Transformer transformer = tFactory.newTransformer();
                DOMSource source = new DOMSource(xmlNode);
                StringWriter writer = new StringWriter();
                transformer.transform(source, new StreamResult(writer));
                Node node = NodeFactory.createLiteral(writer.getBuffer().toString(), dt);
                nodeValue = new NodeValueNode(node);
            }
            nodeValues.add(nodeValue);
        }
        LOG.trace("Evaluation of " + v2 + ": " + nodeValues.size() + " values");
        return nodeValues;
    } catch (Exception ex) {
        LOG.debug("No evaluation for " + xml + ", " + v2, ex);
        throw new ExprEvalException("No evaluation for " + v2, ex);
    }
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:76,代码来源:ITER_XPath.java


示例20: exec

import org.apache.jena.datatypes.TypeMapper; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue json, NodeValue jsonquery) {
    if (json.getDatatypeURI() != null
            && !json.getDatatypeURI().equals(datatypeUri)
            && !json.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
        LOG.warn("The URI of NodeValue1 MUST be"
                + " <" + datatypeUri + "> or"
                + " <http://www.w3.org/2001/XMLSchema#string>. Got <"
                + json.getDatatypeURI() + ">. Returning null.");
    }
    Configuration conf = Configuration.builder()
            .options(Option.ALWAYS_RETURN_LIST).build();

    try {
        List<Object> values = JsonPath
                .using(conf)
                .parse(json.asNode().getLiteralLexicalForm())
                .read(jsonquery.getString());
        List<NodeValue> nodeValues = new ArrayList<>(values.size());
        Gson gson = new Gson();

        int position = 0;
        for (Object value : values) {
            RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(datatypeUri);
            String jsonstring = gson.toJson(value);
            String structure = "{\"element\":elementValue,\"position\":intPos,\"hasNext\":hasNextValue}";

            structure = structure.replaceAll("intPos", String.valueOf(position));
            if (position < values.size() - 1) {
                structure = structure.replaceAll("hasNextValue", "true");
            } else {
                structure = structure.replaceAll("hasNextValue", "false");
            }
            structure = structure.replaceAll("elementValue", jsonstring);
            jsonstring = structure;

            Node node = NodeFactory.createLiteral(jsonstring, dt);
            NodeValue nodeValue = new NodeValueNode(node);
            nodeValues.add(nodeValue);

            position++;
        }
        return nodeValues;
    } catch (Exception ex) {
        LOG.debug("No evaluation for " + json + ", " + jsonquery, ex);
        throw new ExprEvalException("No evaluation for " + json + ", " + jsonquery, ex);
    }
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:49,代码来源:ITER_JSONElement.java



注:本文中的org.apache.jena.datatypes.TypeMapper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Property类代码示例发布时间:2022-05-23
下一篇:
Java ChangeMessageVisibilityBatchRequest类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap