Java 类com.hp.hpl.jena.query.ParameterizedSparqlString 实例源码

项目:openimaj    文件:GeneralJSONRDF.java   
private void addUserParameters(ParameterizedSparqlString pss, User user, USMFStatus status) {
    PQUtils.setPSSIri(pss, Variables.USER.name, createUserIRI(status, user));
    PQUtils.setPSSIri(pss, Variables.PERSON.name, createPersonIRI(status, user));
    PQUtils.setPSSLiteral(pss, Variables.PERSON_NAME.name, user.real_name);
    PQUtils.setPSSLiteral(pss, Variables.PERSON_LOC.name, user.location);
    PQUtils.setPSSLiteral(pss, new String[] { Variables.PERSON_LAT.name, Variables.PERSON_LONG.name }, user.geo);
    PQUtils.setPSSLiteral(pss, Variables.USER_NAME.name, user.name);
    PQUtils.setPSSLiteral(pss, Variables.USER_ID.name, user.id);
    PQUtils.setPSSLiteral(pss, Variables.USER_LANG.name, user.language);
    PQUtils.setPSSLiteral(pss, Variables.PERSON_LANG.name, user.language);
    PQUtils.setPSSLiteral(pss, Variables.USER_DESC.name, user.description);
    PQUtils.setPSSLiteral(pss, Variables.USER_AVATAR.name, user.avatar);
    PQUtils.setPSSLiteral(pss, Variables.USER_SITE.name, user.website);
    PQUtils.setPSSLiteral(pss, Variables.USER_PROF.name, user.profile);
    PQUtils.setPSSLiteral(pss, Variables.USER_FOLLOWERS.name, user.subscribers);
    PQUtils.setPSSLiteral(pss, Variables.USER_FOLLOWING.name, user.subscriptions);
    PQUtils.setPSSLiteral(pss, Variables.USER_POSTS.name, user.postings);
}
项目:uncc2014watsonsim    文件:DBPediaCandidateType.java   
private Query getQuery(String text) {
    ParameterizedSparqlString sparql = new ParameterizedSparqlString(
            "PREFIX : <http://dbpedia.org/resource/>\n"
            + "PREFIX dbo: <http://dbpedia.org/ontology/>\n"
            + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
            + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "select distinct ?kind where {\n"
            + "{?content dbo:wikiPageDisambiguates ?article."
            + " ?article a ?kind_resource.}"
            + "Union"
            + "{?content a ?kind_resource.}"
            + "?kind_resource rdfs:label ?kind."
            + "FILTER ("
                + "langMatches(lang(?kind), 'EN')"
            + ")} limit 10");
    List<String> uris = rdf_label_search.query(text);
    if (uris.size() > 0) sparql.setIri("content", uris.get(0));
    else sparql.setIri("content", "uri:moo:ajklhawkjd");
    return sparql.asQuery();

}
项目:WikiOnto    文件:DissolveGUI.java   
private void getInstances() {
    File metricFile = new File(
            System.getProperty("user.dir") + "/sparql/queries/getInstances.sparql");

    List<String> lines = null;

    try {
        lines = Files.readAllLines(metricFile.toPath());
    } catch (IOException ex) {
        Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null, ex);
    }
    String queryString = "";
    for (String line : lines) {
        queryString += line + System.lineSeparator();
    }
    ParameterizedSparqlString pss = new ParameterizedSparqlString();
    pss.setCommandText(queryString);
    pss.setLiteral("typename", typename);
    data.begin(ReadWrite.READ);
    List<QuerySolution> rlist = null;
    try (QueryExecution qe = QueryExecutionFactory.create(pss.asQuery(), data)) {
        ResultSet results = qe.execSelect();
        rlist = ResultSetFormatter.toList(results);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
        e.printStackTrace();
    }
    instances = new String[rlist.size()];
    for(int j = 0; j < rlist.size(); j++){
        instances[j] = rlist.get(j).getLiteral("iname").getString();
    }
    data.end();
}
项目:WikiOnto    文件:DissolveGUI.java   
private void getSubtypes() {
    File metricFile = new File(
            System.getProperty("user.dir") + "/sparql/queries/getSubtypes.sparql");

    List<String> lines = null;

    try {
        lines = Files.readAllLines(metricFile.toPath());
    } catch (IOException ex) {
        Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null, ex);
    }
    String queryString = "";
    for (String line : lines) {
        queryString += line + System.lineSeparator();
    }
    ParameterizedSparqlString pss = new ParameterizedSparqlString();
    pss.setCommandText(queryString);
    pss.setLiteral("typename", typename);
    data.begin(ReadWrite.READ);
    List<QuerySolution> rlist = null;
    try (QueryExecution qe = QueryExecutionFactory.create(pss.asQuery(), data)) {
        ResultSet results = qe.execSelect();
        rlist = ResultSetFormatter.toList(results);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
        e.printStackTrace();
    }
    data.end();
    subtypes= new String[rlist.size()];
    for(int j = 0; j < rlist.size(); j++){
        subtypes[j] = rlist.get(j).getLiteral("sname").getString();
    }
}
项目:WikiOnto    文件:TransformationProcessor.java   
public long transform(String tfilename, Map<String,String> parameter){
    File tfile = new File(System.getProperty("user.dir")+"/sparql/transformations/"+tfilename);
    String transformation = "";
    try {
        List<String> lines = Files.readAllLines(tfile.toPath());
        for(String line : lines){
            transformation+=line+"\n";
        }
    } catch (IOException ex) {
        System.err.println("Exception transforming:"+tfilename);;
    }
    dataset.begin(ReadWrite.WRITE);
    Graph graph = dataset.asDatasetGraph().getDefaultGraph();
    long size = graph.size();
    ParameterizedSparqlString pss = new ParameterizedSparqlString();
    pss.setCommandText(transformation);
    for(String key: parameter.keySet()){
        String query = pss.asUpdate().toString();
        if(!parameter.get(key).contains("http://")){
            pss.setLiteral(key, parameter.get(key).trim());
        }else{
            pss.setIri(key, parameter.get(key).trim());
        }
        if(query.equals(pss.asUpdate().toString())) {
            JOptionPane.showMessageDialog(null,"Querynames are flawed. This should not happen.");
            System.err.println(pss.toString());
            return 0;
        }
    }
    UpdateAction.execute(pss.asUpdate(), graph);
    size = graph.size() - size;
    dataset.commit();
    return size;
}
项目:Marvin    文件:DBPediaQuery.java   
public static void main(String[] args) {
    ParameterizedSparqlString qs = new ParameterizedSparqlString(""
            + "prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#>\n"
            + "prefix dbpedia-owl: <http://dbpedia.org/ontology/>\n"
            + "prefix dbpprop: <http://dbpedia.org/property/>\n"
            + "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            +
            "SELECT DISTINCT * \n" + "WHERE { \n"
            + " ?resource  rdfs:label ?label ;\n"
            + " dbpedia-owl:abstract ?abstract .\n"
            + "FILTER ( lang(?abstract) = 'en' ) \n" + "}");

    Literal london = ResourceFactory.createLangLiteral("London", "en");
    qs.setParam("label", london);

    System.out.println(qs);

    QueryExecution exec = QueryExecutionFactory.sparqlService(
            "http://dbpedia.org/sparql", qs.asQuery());
    ResultSet results = ResultSetFactory.copyResults(exec.execSelect());

    while (results.hasNext()) {
        QuerySolution sol = (QuerySolution) results.next();
        RDFNode node = sol.get("resource");
        System.out.println(sol.get("?abstract"));
        System.out.println(node);
    }
    // A simpler way of printing the results.
    ResultSetFormatter.out(results);
}
项目:statistics2cubes    文件:VirtuosoDao.java   
public String deleteCube(String namedGraph) {
    VirtGraph set = new VirtGraph(ENDPOINT, USER, PW);
       ParameterizedSparqlString prepareQuery = new ParameterizedSparqlString(CLEAR_GRAPH);
       prepareQuery.setIri("g", namedGraph);
    VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(prepareQuery.toString(), set);
    vur.exec();

    return null;
}
项目:openimaj    文件:LanguageDetectionMode.java   
@Override
public RDFAnalysisProvider rdfAnalysisProvider() {
    return new RDFAnalysisProvider() {
        private static final String DETECTED_LANGUAGE_INSERT_SPARQL = "/org/openimaj/tools/twiiter/rdf/detected_language_insert.sparql";
        private String query;

        @Override
        public void addAnalysis(Model m, Resource socialEvent, GeneralJSON analysisSource) {
            final Map<String, Object> analysis = analysisSource.getAnalysis(LANGUAGES);
            if (analysis == null)
                return;

            final ParameterizedSparqlString pss = new ParameterizedSparqlString(query); // wasteful?
                                                                                        // makes
                                                                                        // it
                                                                                        // threadsafe
                                                                                        // but
                                                                                        // is
                                                                                        // it
                                                                                        // bad?
            pss.setParam("socialEvent", socialEvent);
            final Resource langNode = m.createResource();
            pss.setParam("langid", langNode);
            pss.setLiteral("language", analysis.get("language").toString());
            pss.setLiteral("confidence", (Double) analysis.get("confidence"));
            UpdateAction.execute(pss.asUpdate(), m);
        }

        @Override
        public void init() {
            try {
                query = FileUtils.readall(GeneralJSONRDF.class.getResourceAsStream(DETECTED_LANGUAGE_INSERT_SPARQL));
            } catch (final IOException e) {
                throw new RuntimeException(e);
            }

        }
    };
}
项目:openimaj    文件:PQUtils.java   
/**
 * Set a {@link ParameterizedSparqlString} literal
 *
 * @param pss
 * @param strings
 * @param geo
 */
public static void setPSSLiteral(ParameterizedSparqlString pss, String[] strings, double[] geo) {
    for (int i = 0; i < strings.length; i++) {
        if (geo == null) {
            setNull(pss, strings[i]);
        }
        else {
            pss.setLiteral(strings[i], geo[i]);
        }
    }
}
项目:openimaj    文件:PQUtils.java   
/**
 * Set a {@link ParameterizedSparqlString} literal
 *
 * @param pss
 * @param name
 * @param lit
 */
public static void setPSSLiteral(ParameterizedSparqlString pss, String name, String lit) {
    if (lit != null)
        pss.setLiteral(name, lit);
    else
        setNull(pss, name);

}
项目:openimaj    文件:PQUtils.java   
/**
 * @param pss
 * @param name
 * @param iri
 */
public static void setPSSIri(ParameterizedSparqlString pss, String name, String iri) {
    if (iri != null)
        pss.setIri(name, iri);
    else
        setNull(pss, name);
}
项目:openimaj    文件:PQUtils.java   
/**
 * @param pss
 * @param name
 * @param iri
 */
public static void setPSSResource(ParameterizedSparqlString pss, String name, Resource iri) {
    if (iri != null)
        pss.setParam(name, iri);
    else
        setNull(pss, name);
}
项目:gerbil    文件:DBpediaToWikiId.java   
/**
 * The Wikipedia Id or -1 if the Id couldn't be retrieved.
 * 
 * FIXME The method throws an exception for "http://DBpedia.org/resource/Origin_of_the_name_"Empire_State"". this
 * might be happen because of the quotes inside the URI.
 * 
 * @param dbpediaUri
 * @return
 */
@Deprecated
public static int getIdFromDBpedia(String dbpediaUri) {
    int id = -1;
    ParameterizedSparqlString query = new ParameterizedSparqlString(
            "SELECT ?id WHERE { ?dbpedia dbo:wikiPageID ?id .}", prefixes);
    query.setIri("dbpedia", dbpediaUri);
    QueryExecution qexec = null;
    try {
        qexec = QueryExecutionFactory.create(query.asQuery(),
                model);
    } catch (QueryParseException e) {
        LOGGER.error("Got a bad dbpediaUri \"" + dbpediaUri
                + "\" which couldn't be parse inside of a SPARQL query. Returning -1.", e);
        return id;
    }
    ResultSet result = qexec.execSelect();
    if (result.hasNext()) {
        id = result.next().get("id").asLiteral().getInt();
        return id;
    }
    qexec = QueryExecutionFactory.sparqlService(
            "http://dbpedia.org/sparql", query.asQuery());
    result = qexec.execSelect();
    if (result.hasNext()) {
        id = result.next().get("id").asLiteral().getInt();
        model.add(new StatementImpl(model.createResource(dbpediaUri), model
                .createProperty("http://dbpedia.org/ontology/wikiPageID"),
                model.createTypedLiteral(id)));
        return id;
    }

    model.add(new StatementImpl(model.createResource(dbpediaUri), model
            .createProperty("http://dbpedia.org/ontology/wikiPageID"),
            model.createTypedLiteral(id)));
    return id;
}
项目:cobalt    文件:CompatibleResourceFinder.java   
@Override
protected String getQuery(final Functionality request, final Model model) {
  final ParameterizedSparqlString pss = new ParameterizedSparqlString(
      ResourceCache.getInstance().get("/sparql/compatible-functionalities.rq"));
  pss.setParam("request", IdentifiableExternalizer.externalize(request, model));
  return pss.toString();
}
项目:cobalt    文件:CompatibleResourceFinder.java   
@Override
protected String getQuery(final Property request, final Model model) {
  final ParameterizedSparqlString pss = new ParameterizedSparqlString(
      ResourceCache.getInstance().get("/sparql/compatible-properties.rq"));
  pss.setParam("request", IdentifiableExternalizer.externalize(request.getType(), model));
  return pss.toString();
}
项目:OWL2SPARQL    文件:OWLAxiomToSPARQLConverter.java   
@Override
public void visit(OWLAsymmetricObjectPropertyAxiom axiom) {
    String propertyURI = axiom.getProperty().asOWLObjectProperty().toStringID();
    ParameterizedSparqlString query = new ParameterizedSparqlString("?s ?p ?o . FILTER NOT EXISTS{?o ?p ?s}");
    query.setIri("p", propertyURI);
    sparql += query.toString();
}
项目:OWL2SPARQL    文件:OWLAxiomToSPARQLConverter.java   
@Override
public void visit(OWLSymmetricObjectPropertyAxiom axiom) {
    String propertyURI = axiom.getProperty().asOWLObjectProperty().toStringID();
    ParameterizedSparqlString query = new ParameterizedSparqlString("?s ?p ?o . ?o ?p ?s .");
    query.setIri("p", propertyURI);
    sparql += query.toString();
}
项目:OWL2SPARQL    文件:OWLAxiomToSPARQLConverter.java   
@Override
public void visit(OWLTransitiveObjectPropertyAxiom axiom) {
    ParameterizedSparqlString template = new ParameterizedSparqlString(
            subjectVar + " ?p ?o1 . ?o1 ?p ?o . " + subjectVar + " ?p " + objectVar);
    template.setIri("p", axiom.getProperty().asOWLObjectProperty().toStringID());
    sparql += template.toString();
}
项目:semanticMDR    文件:SerializationService.java   
@GET
@Path("/dex")
@Produces({ WebUtil.MEDIA_TYPE_APPLICATION_NTRIPLE,
        WebUtil.MEDIA_TYPE_APPLICATION_RDFJSON,
        WebUtil.MEDIA_TYPE_APPLICATION_RDFXML, MediaType.TEXT_PLAIN,
        WebUtil.MEDIA_TYPE_TEXT_N3, WebUtil.MEDIA_TYPE_TEXT_TURTLE })
public Response dexSerialization(@QueryParam("id") String uuid,
        @Context Request request) {

    Variant variant = request.selectVariant(WebUtil.VARIANTS);
    MediaType mediaType = variant.getMediaType();

    Repository repository = RepositoryManager.getInstance().getRepository();
    OntModel ontModel = repository.getMDRDatabase().getOntModel();
    String queryString;

    File file = new File(
            "../web/src/main/resources/rest/dex-serialization-query.rq");
    try {
        queryString = FileUtils.readFileToString(file);
    } catch (IOException e) {
        logger.error("File with dex serialization query could not be found ");
        return Response.serverError().build();
    }

    ParameterizedSparqlString query = new ParameterizedSparqlString(
            queryString);
    query.setLiteral("uuid", ResourceFactory.createTypedLiteral(uuid));
    QueryExecution qe = QueryExecutionFactory.create(query.asQuery(),
            ontModel);
    Model resultModel = qe.execConstruct();

    graphStream.setModel(resultModel);
    graphStream.setLanguage(WebUtil.getSerializationLanguage(mediaType
            .toString()));

    return Response.ok(graphStream).build();
}
项目:semanticMDR    文件:ContextService.java   
@GET
@Path("/all")
@Produces({ WebUtil.MEDIA_TYPE_APPLICATION_NTRIPLE,
        WebUtil.MEDIA_TYPE_APPLICATION_RDFJSON,
        WebUtil.MEDIA_TYPE_APPLICATION_RDFXML, MediaType.TEXT_PLAIN,
        WebUtil.MEDIA_TYPE_TEXT_N3, WebUtil.MEDIA_TYPE_TEXT_TURTLE })
public Response getAllContexts(@Context Request request) {

    Variant variant = request.selectVariant(WebUtil.VARIANTS);
    MediaType mediaType = variant.getMediaType();

    Repository repository = RepositoryManager.getInstance().getRepository();
    OntModel ontModel = repository.getMDRDatabase().getOntModel();

    String queryString;
    File file = new File(QUERY_FILE_GET_ALL_CONTEXTS);
    try {
        queryString = FileUtils.readFileToString(file);
    } catch (IOException e) {
        logger.error("File with context serialization query could not be found ");
        return Response.serverError().build();
    }

    ParameterizedSparqlString query = new ParameterizedSparqlString(
            queryString);
    QueryExecution qe = QueryExecutionFactory.create(query.asQuery(),
            ontModel);
    Model resultModel = qe.execConstruct();

    graphStream.setModel(resultModel);
    graphStream.setLanguage(WebUtil.getSerializationLanguage(mediaType
            .toString()));

    return Response.ok(graphStream).build();
}
项目:semanticMDR    文件:ContextService.java   
@GET
@Path("/{contextid}/de")
@Produces({ WebUtil.MEDIA_TYPE_APPLICATION_NTRIPLE,
        WebUtil.MEDIA_TYPE_APPLICATION_RDFJSON,
        WebUtil.MEDIA_TYPE_APPLICATION_RDFXML, MediaType.TEXT_PLAIN,
        WebUtil.MEDIA_TYPE_TEXT_N3, WebUtil.MEDIA_TYPE_TEXT_TURTLE })
public Response getDataElements(@PathParam("contextid") String contextId,
        @Context Request request) {

    Variant variant = request.selectVariant(WebUtil.VARIANTS);
    MediaType mediaType = variant.getMediaType();

    Repository repository = RepositoryManager.getInstance().getRepository();
    OntModel ontModel = repository.getMDRDatabase().getOntModel();

    String queryString;
    File file = new File(QUERY_FILE_GET_ALL_FROM_CONTEXT);
    try {
        queryString = FileUtils.readFileToString(file);
    } catch (IOException e) {
        logger.error("File with context serialization query could not be found ");
        return Response.serverError().build();
    }

    ParameterizedSparqlString query = new ParameterizedSparqlString(
            queryString);
    query.setLiteral("uuid", ResourceFactory.createTypedLiteral(contextId));
    QueryExecution qe = QueryExecutionFactory.create(query.asQuery(),
            ontModel);
    Model resultModel = qe.execConstruct();

    graphStream.setModel(resultModel);
    graphStream.setLanguage(WebUtil.getSerializationLanguage(mediaType
            .toString()));

    return Response.ok(graphStream).build();
}
项目:statistics2cubes    文件:VirtuosoDao.java   
public String importUpload(Model model, String context) {
//        String content = convertModelToString(model);
//        VirtGraph set = new VirtGraph(context, ENDPOINT, USER, PW);
//        Model m = ModelFactory.createDefaultModel();
//        m.read(new StringReader(content), null, Lang.N3.getName());
//        List<Triple> triples = new ArrayList<Triple>();
//        StmtIterator stmtIt = m.listStatements();
//
//        while (stmtIt.hasNext()) {
//            triples.add(stmtIt.nextStatement().asTriple());
//        }
//
//        GraphUtil.add(set, triples);
//
//        return null;


        VirtGraph set = new VirtGraph(context, ENDPOINT, USER, PW);
        StmtIterator stmtIt = model.listStatements();

        int i = 0;
        Model tempModel = ModelFactory.createDefaultModel();

        while (stmtIt.hasNext()) {
            tempModel.add(stmtIt.next());
            i++;

            if (i == BATCH_SIZE || !stmtIt.hasNext()) {
                System.out.println("batch");
                String query = "INSERT INTO ?g {";
                query += convertModelToString(tempModel);
                query += "}";

                ParameterizedSparqlString prepareQuery = new ParameterizedSparqlString(query);
                prepareQuery.setIri("g", context);
                VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(prepareQuery.toString(), set);
                vur.exec();
                i = 0;
                tempModel = ModelFactory.createDefaultModel();
            }
        }

        return null;
    }
项目:music-genres    文件:WikidataApiClient.java   
/**
     * Sample query: "https://www.wikidata.org/wiki/Q6607" for guitar
     * @param id
     * @return DBPedia response
     */
    public String getWikidataLabelById(String id) {

        String res = "";

        ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
                "prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#>\n" +
                "prefix wd: <http://www.wikidata.org/entity/>\n" +
                "\n" +
                "select *\n" +
                "where {\n" +
                "         wd:Q" + id + " rdfs:label ?label .\n" +
                "         FILTER (LANG(?label) = 'en') .\n" + 
                "      }\n" + 
                "LIMIT 1" 
                );

//        Literal labelLiteral = ResourceFactory.createLangLiteral( label, "en" );
//        qs.setParam("label", labelLiteral);

        log.debug( qs );

        QueryExecution exec = QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT, qs.asQuery());

        ResultSet resultSet = exec.execSelect();

        // Normally you'd just do results = exec.execSelect(), but I want to 
        // use this ResultSet twice, so I'm making a copy of it.  
        ResultSet results = ResultSetFactory.copyResults( resultSet );

        while ( results.hasNext() ) {
            // As RobV pointed out, don't use the `?` in the variable
            // name here. Use *just* the name of the variable.
//            System.out.println( results.next().get( "resource" ));
            QuerySolution resQs = results.next();
            res = res + resQs.get( "resource" ) + "#";
            res = res + resQs.get( "description" );
//            System.out.println( resQs.get( "resource" ));
//            System.out.println( resQs.get( "description" ));
        }

        // A simpler way of printing the results.
        ResultSetFormatter.out( results );
//        return results.toString();
        if (res.equals(""))
            res = "#";
        return res;
    }
项目:music-genres    文件:DBPediaApiClient.java   
/**
     * Sample query: "http://dbpedia.org/page/Chicago_blues"
     * @param label
     * @return DBPedia response
     */
    public String queryDBPedia(String label) {

        String res = "";

        ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
                "prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#>\n" +
                "\n" +
                "select ?resource ?description where {\n" +
//                "   ?resource rdfs:label \"" + label + "\"@en .\n" +
                "     ?resource rdfs:label ?label .\n" +
                "     ?resource rdfs:comment ?description .\n" +
                "     FILTER (LANG(?description) = 'en') .\n" + 
//                "select ?resource where {\n" +
//                "  ?resource rdfs:label ?label\n" +
                "}" );

        Literal labelLiteral = ResourceFactory.createLangLiteral( label, "en" );
        qs.setParam("label", labelLiteral);

        System.out.println( qs );

        QueryExecution exec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", qs.asQuery());

        // Normally you'd just do results = exec.execSelect(), but I want to 
        // use this ResultSet twice, so I'm making a copy of it.  
        ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );

        while ( results.hasNext() ) {
            // As RobV pointed out, don't use the `?` in the variable
            // name here. Use *just* the name of the variable.
//            System.out.println( results.next().get( "resource" ));
            QuerySolution resQs = results.next();
            res = res + resQs.get( "resource" ) + "#";
            res = res + resQs.get( "description" );
//            System.out.println( resQs.get( "resource" ));
//            System.out.println( resQs.get( "description" ));
        }

        // A simpler way of printing the results.
        ResultSetFormatter.out( results );
//        return results.toString();
        if (res.equals(""))
            res = "#";
        return res;
    }
项目:music-genres    文件:DBPediaApiClient.java   
/**
     * Sample query: "http://dbpedia.org/page/Chicago_blues"
     * @param label
     * @return DBPedia response
     */
    public String queryDBPediaByLanguage(String label, String language) {

        String res = "";

        ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
                "prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#>\n" +
                "\n" +
                "select ?resource ?description where {\n" +
//                "   ?resource rdfs:label \"" + label + "\"@en .\n" +
                "     ?resource rdfs:label ?label .\n" +
                "     ?resource rdfs:comment ?description .\n" +
                "     FILTER (LANG(?description) = '" + language + "') .\n" + 
//                "select ?resource where {\n" +
//                "  ?resource rdfs:label ?label\n" +
                "}" );

        Literal labelLiteral = ResourceFactory.createLangLiteral( label, language );
        qs.setParam("label", labelLiteral);

        System.out.println( qs );

        QueryExecution exec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", qs.asQuery());

        // Normally you'd just do results = exec.execSelect(), but I want to 
        // use this ResultSet twice, so I'm making a copy of it.  
        ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );

        while ( results.hasNext() ) {
            // As RobV pointed out, don't use the `?` in the variable
            // name here. Use *just* the name of the variable.
//            System.out.println( results.next().get( "resource" ));
            QuerySolution resQs = results.next();
            res = res + resQs.get( "resource" ) + "#";
            res = res + resQs.get( "description" );
//            System.out.println( resQs.get( "resource" ));
//            System.out.println( resQs.get( "description" ));
        }

        // A simpler way of printing the results.
        ResultSetFormatter.out( results );
//        return results.toString();
        if (res.equals(""))
            res = "#";
        return res;
    }
项目:semanticMDR    文件:DataElementService.java   
@GET
@Path("/{deid}/es")
@Produces(MediaType.APPLICATION_JSON)
public Response getExtractionSpec(
        @QueryParam("specification-format") String specificationFormat,
        @QueryParam("content-model") String contentModel,
        @PathParam("deid") String deid) {
    Repository repository = RepositoryManager.getInstance().getRepository();
    OntModel ontModel = repository.getMDRDatabase().getOntModel();
    List<String> extractionSpecifications = new ArrayList<String>();

    if (specificationFormat == null || contentModel == null) {
        throw new WebApplicationException(Status.NOT_ACCEPTABLE);
    }

    File getExtractionFile = new File(QUERY_FILE_GET_EXTRACTIONS);
    String queryString = "";
    try {
        queryString = FileUtils.readFileToString(getExtractionFile);
    } catch (IOException e) {
        logger.error("File with context serialization query could not be found ");
        return Response.serverError().build();
    }
    ParameterizedSparqlString query = new ParameterizedSparqlString(
            queryString);
    query.setLiteral("uuid", ResourceFactory.createTypedLiteral(deid));
    query.setLiteral("specFormat",
            ResourceFactory.createTypedLiteral(specificationFormat));
    query.setLiteral("contentModel",
            ResourceFactory.createTypedLiteral(contentModel));
    QueryExecution qe = QueryExecutionFactory.create(query.asQuery(),
            ontModel);

    String spec = "";
    ResultSet rs = qe.execSelect();
    while (rs.hasNext()) {
        QuerySolution qs = rs.next();
        spec = qs.getLiteral("extractionSpec").getString();
        if (spec != null && !spec.equals("")) {
            extractionSpecifications.add(spec);
        }
    }

    return Response.ok(extractionSpecifications).build();
}
项目:openimaj    文件:PQUtils.java   
/**
 * Set a {@link ParameterizedSparqlString} null
 *
 * @param pss
 * @param name
 */
public static void setNull(ParameterizedSparqlString pss, String name) {
    pss.setLiteral(name, Node.NULL.toString());
}
项目:openimaj    文件:PQUtils.java   
/**
 * Set a {@link ParameterizedSparqlString} literal
 *
 * @param pss
 * @param name
 * @param d
 */
public static void setPSSLiteral(ParameterizedSparqlString pss, String name, double d) {
    pss.setLiteral(name, d);
}
项目:openimaj    文件:PQUtils.java   
/**
 * Set a {@link ParameterizedSparqlString} literal
 *
 * @param pss
 * @param name
 * @param d
 */
public static void setPSSLiteral(ParameterizedSparqlString pss, String name, int d) {
    pss.setLiteral(name, d);
}
项目:openimaj    文件:PQUtils.java   
/**
 * Construct a {@link ParameterizedSparqlString}
 * 
 * @param query
 * @param m
 * @return the {@link ParameterizedSparqlString}
 */
public static ParameterizedSparqlString constructPQ(String query, Model m) {
    final ParameterizedSparqlString pss = new ParameterizedSparqlString(query, m);
    return pss;
}