Package org.apache.clerezza.rdf.core.sparql

Examples of org.apache.clerezza.rdf.core.sparql.SolutionMapping


        }

        ResultSet result = tcManager.executeSparqlQuery(query, ci.getMetadata());
        List<String> values = new ArrayList<String>();
        while (result.hasNext()) {
            SolutionMapping sol = result.next();
            Resource res = sol.get(fieldName.toString());
            if (res == null) continue;
            String value = res.toString();
            if (res instanceof Literal) {
                value = ((Literal) res).getLexicalForm();
            }
View Full Code Here


        }

        ResultSet resultSet = tcManager.executeSparqlQuery(selectQuery, this.getEnhancementGraph());
        MGraph metadata = new IndexedMGraph();
        while (resultSet.hasNext()) {
            SolutionMapping mapping = resultSet.next();
            UriRef ref = (UriRef) mapping.get("enhID");
            Iterator<Triple> tripleItr = this.getEnhancementGraph().filter(ref, null, null);
            while (tripleItr.hasNext()) {
                Triple triple = tripleItr.next();
                metadata.add(triple);
            }
View Full Code Here

        Collection<CalaisEntityOccurrence> result = new ArrayList<CalaisEntityOccurrence>();
        try {
            SelectQuery sQuery = (SelectQuery) QueryParser.getInstance().parse(query);
            ResultSet rs = tcManager.executeSparqlQuery(sQuery, model);
            while (rs.hasNext()) {
                SolutionMapping row = rs.next();
                CalaisEntityOccurrence occ = new CalaisEntityOccurrence();
                Resource disambiguated = row.get("did");
                occ.id = (disambiguated == null ? row.get("id") : disambiguated);
                if (onlyNERMode) {
                    occ.type = row.get("type");
                }
                else {
                    occ.type = (disambiguated == null ? row.get("type") : row.get("dtype"));
                }
                if (calaisTypeMap != null) {
                    UriRef mappedType = calaisTypeMap.get(occ.type);
                    if (mappedType != null) {
                        occ.type = mappedType;
                    }
                }
                occ.name = ((Literal)row.get("name")).getLexicalForm();
                occ.exact = ((Literal)row.get("exact")).getLexicalForm();
                //TODO for html the offsets might not be those of the original document but refer to a cleaned up version?
                occ.offset = Integer.valueOf(((Literal) row.get("offset")).getLexicalForm());
                // remove brackets
                occ.context = ((Literal) row.get("context")).getLexicalForm().replaceAll("[\\[\\]]", "");
                occ.length = Integer.valueOf(((Literal) row.get("length")).getLexicalForm());
                if (row.get("score") != null) {
                    occ.relevance = Double.valueOf(((Literal) row.get("score")).getLexicalForm());
                }
                result.add(occ);
            }
        } catch (ParseException e) {
            throw new EngineException("Unable to parse SPARQL query for processing OpenCalais results",e);
View Full Code Here

        Collection<CalaisEntityOccurrence> result = new ArrayList<CalaisEntityOccurrence>();
        try {
            SelectQuery sQuery = (SelectQuery) QueryParser.getInstance().parse(query);
            ResultSet rs = tcManager.executeSparqlQuery(sQuery, model);
            while (rs.hasNext()) {
                SolutionMapping row = rs.next();
                CalaisEntityOccurrence occ = new CalaisEntityOccurrence();
                Resource disambiguated = row.get("did");
                occ.id = (disambiguated == null ? row.get("id") : disambiguated);
                if (onlyNERMode) {
                    occ.type = row.get("type");
                }
                else {
                    occ.type = (disambiguated == null ? row.get("type") : row.get("dtype"));
                }
                if (calaisTypeMap != null) {
                    UriRef mappedType = calaisTypeMap.get(occ.type);
                    if (mappedType != null) {
                        occ.type = mappedType;
                    }
                }
                occ.name = ((Literal)row.get("name")).getLexicalForm();
                occ.exact = ((Literal)row.get("exact")).getLexicalForm();
                //TODO for html the offsets might not be those of the original document but refer to a cleaned up version?
                occ.offset = Integer.valueOf(((Literal) row.get("offset")).getLexicalForm());
                // remove brackets
                occ.context = ((Literal) row.get("context")).getLexicalForm().replaceAll("[\\[\\]]", "");
                occ.length = Integer.valueOf(((Literal) row.get("length")).getLexicalForm());
                if (row.get("score") != null) {
                    occ.relevance = Double.valueOf(((Literal) row.get("score")).getLexicalForm());
                }
                result.add(occ);
            }
        } catch (ParseException e) {
            // TODO Auto-generated catch block
View Full Code Here

    sci.getMetadata();
    ResultSet result = tcManager.executeSparqlQuery(query,
        sci.getMetadata());
    List<String> values = new ArrayList<String>();
    while (result.hasNext()) {
      SolutionMapping sol = result.next();
      Resource res = sol.get(fieldName.toString());
      if (res == null)
        continue;
      String value = res.toString();
      if (res instanceof Literal) {
        value = ((Literal) res).getLexicalForm();
View Full Code Here

    ResultSet resultSet = tcManager.executeSparqlQuery(selectQuery,
        this.getEnhancementGraph());
    MGraph metadata = new SimpleMGraph();
    while (resultSet.hasNext()) {
      SolutionMapping mapping = resultSet.next();
      UriRef ref = (UriRef) mapping.get("enhID");
      Iterator<Triple> tripleItr = this.getEnhancementGraph().filter(ref,
          null, null);
      while (tripleItr.hasNext()) {
        Triple triple = tripleItr.next();
        metadata.add(triple);
View Full Code Here

            doc.appendChild(root);
            Element head = doc.createElement("head");
            root.appendChild(head);
            Set<Object> variables = new HashSet<Object>();
            Element results = doc.createElement("results");
            SolutionMapping solutionMapping = null;
            while (queryResult.hasNext()) {
                solutionMapping = queryResult.next();               
                createResultElement(solutionMapping, results, doc);               
            }
            createVariable(solutionMapping, head, doc);
View Full Code Here

     *
     */
    private Element createResultsElement(ResultSet resultSet, Document doc) {
        Element results = doc.createElement("results");
        while (resultSet.hasNext()) {
            SolutionMapping solutionMap = resultSet.next();
            Set<Variable> keys = solutionMap.keySet();
            Element result = doc.createElement("result");
            results.appendChild(result);

            for (Variable key : keys) {
                Element bindingElement = doc.createElement("binding");
                bindingElement.setAttribute("name", key.getName());
                bindingElement.appendChild(createValueElement(
                        (Resource) solutionMap.get(key), doc));
                result.appendChild(bindingElement);
            }
        }
        return results;
    }
View Full Code Here

        Element head = doc.createElement("head");
        root.appendChild(head);

        // result set
        Element results = doc.createElement("results");
        SolutionMapping solutionMapping = null;
        while (rs.hasNext()) {
            solutionMapping = rs.next();
            createResultElement(solutionMapping, results, doc);
        }
        createVariable(solutionMapping, head, doc);
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.sparql.SolutionMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.