Java从fuseki服务器错误解析内容

时间:2017-01-16 20:17:38

标签: java rdf ontology fuseki

我发现此代码here应解析我上传RDF文件的fuseki服务器中的内容,但它返回404 Not Found ...

为什么我收到此错误,因为我可以使用代码中的路径从服务器访问我上传的文件?

我的RDF上传到fuseki服务器的路径是http://localhost:3030/Date/data/,这是它包含的内容:

@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix admin: <http://webns.net/mvcb/> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix foaf:  <http://xmlns.com/foaf/0.1/> .

<http://localhost:3030/Date/data>
        a                     foaf:PersonalProfileDocument ;
        admin:errorReportsTo  <mailto:leigh@ldodds.com> ;
        admin:generatorAgent  <http://www.ldodds.com/foaf/foaf-a-matic> ;
        foaf:maker            <http://localhost:3030/Date/data#me> ;
        foaf:primaryTopic     <http://localhost:3030/Date/data#me> .

<http://localhost:3030/Date/data#me>
        a                       foaf:Person ;
        foaf:family_name        "Smith" ;
        foaf:givenname          "John" ;
        foaf:homepage           <http://localhost:3030/Date/site.net> ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "13add4a38db79b6645aca8dafe59051d971c38e6" ;
                                  foaf:name          "Mary"
                                ] ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "0072d6deb958659e205919ec647f3432cf75680d" ;
                                  foaf:name          "George"
                                ] ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "d0aba3272918de44d34185558f06a507b8efe49c" ;
                                  foaf:name          "Lora"
                                ] ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "13add4a38db79b6645aca8dafe59051d971c38e6" ;
                                  foaf:name          "Mary"
                                ] ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "0072d6deb958659e205919ec647f3432cf75680d" ;
                                  foaf:name          "George"
                                ] ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "d0aba3272918de44d34185558f06a507b8efe49c" ;
                                  foaf:name          "Lora"
                                ] ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "13add4a38db79b6645aca8dafe59051d971c38e6" ;
                                  foaf:name          "Mary"
                                ] ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "0072d6deb958659e205919ec647f3432cf75680d" ;
                                  foaf:name          "George"
                                ] ;
        foaf:knows              [ a                  foaf:Person ;
                                  foaf:mbox_sha1sum  "d0aba3272918de44d34185558f06a507b8efe49c" ;
                                  foaf:name          "Lora"
                                ] ;
        foaf:mbox_sha1sum       "77d0a8b957b9e316620d66631e1254e906148164" ;
        foaf:name               "John Smith" ;
        foaf:nick               "Johnny" ;
        foaf:phone              <tel:0745158477> ;
        foaf:schoolHomepage     <http://localhost:3030/Date/Harvard> ;
        foaf:title              "Dr" ;
        foaf:workInfoHomepage   <http://localhost:3030/Date/development> ;
        foaf:workplaceHomepage  <http://localhost:3030/Date/work> .

<http://localhost:3030/Date/data/example1> {
    <http://localhost:3030/Date/data?graph=example1>
            a                     foaf:PersonalProfileDocument ;
            admin:errorReportsTo  <mailto:leigh@ldodds.com> ;
            admin:generatorAgent  <http://www.ldodds.com/foaf/foaf-a-matic> ;
            foaf:maker            <http://localhost:3030/Date/data?graph=example1#me> ;
            foaf:primaryTopic     <http://localhost:3030/Date/data?graph=example1#me> .

    <http://localhost:3030/Date/data?graph=example1#me>
            a                       foaf:Person ;
            foaf:family_name        "V" ;
            foaf:givenname          "George" ;
            foaf:homepage           <http://localhost:3030/Date/betacoding.net> ;
            foaf:knows              [ a                  foaf:Person ;
                                      rdfs:seeAlso       <http://localhost:3030/Date/Charlie> ;
                                      foaf:mbox_sha1sum  "c7856d7a98889cee78a21245301a560e8f74d191" ;
                                      foaf:name          "John"
                                    ] ;
            foaf:knows              [ a                  foaf:Person ;
                                      rdfs:seeAlso       <http://localhost:3030/Date/Margaret> ;
                                      foaf:mbox_sha1sum  "a61c03838106b21fc083e7bc65e76c511c549d22" ;
                                      foaf:name          "Mary"
                                    ] ;
            foaf:knows              [ a                  foaf:Person ;
                                      rdfs:seeAlso       <http://localhost:3030/Date/John> ;
                                      foaf:mbox_sha1sum  "27f94c268f1a1c6004be361f4045d43c3745c0de" ;
                                      foaf:name          "Charlie"
                                    ] ;
            foaf:mbox_sha1sum       "b01b5835fa8ae7b7582968a7ecacb9b85503a6c9" ;
            foaf:name               "George V" ;
            foaf:nick               "jorch" ;
            foaf:phone              <tel:123456> ;
            foaf:schoolHomepage     <http://localhost:3030/Date/a school> ;
            foaf:title              "Dr" ;
            foaf:workInfoHomepage   <http://localhost:3030/Date/development> ;
            foaf:workplaceHomepage  <http://localhost:3030/Date/work> .
}

<http://localhost:3030/Date/data/test> {
    <http://localhost:3030/Date/data?graph=test>
            a                     foaf:PersonalProfileDocument ;
            admin:errorReportsTo  <mailto:leigh@ldodds.com> ;
            admin:generatorAgent  <http://www.ldodds.com/foaf/foaf-a-matic> ;
            foaf:maker            <http://localhost:3030/Date/data?graph=test#me> ;
            foaf:primaryTopic     <http://localhost:3030/Date/data?graph=test#me> .

    <http://localhost:3030/Date/data?graph=test#me>
            a                       foaf:Person ;
            foaf:family_name        "V" ;
            foaf:givenname          "George" ;
            foaf:homepage           <http://localhost:3030/Date/betacoding.net> ;
            foaf:knows              [ a                  foaf:Person ;
                                      rdfs:seeAlso       <http://localhost:3030/Date/Charlie> ;
                                      foaf:mbox_sha1sum  "c7856d7a98889cee78a21245301a560e8f74d191" ;
                                      foaf:name          "John"
                                    ] ;
            foaf:knows              [ a                  foaf:Person ;
                                      rdfs:seeAlso       <http://localhost:3030/Date/Margaret> ;
                                      foaf:mbox_sha1sum  "a61c03838106b21fc083e7bc65e76c511c549d22" ;
                                      foaf:name          "Mary"
                                    ] ;
            foaf:knows              [ a                  foaf:Person ;
                                      rdfs:seeAlso       <http://localhost:3030/Date/John> ;
                                      foaf:mbox_sha1sum  "27f94c268f1a1c6004be361f4045d43c3745c0de" ;
                                      foaf:name          "Charlie"
                                    ] ;
            foaf:mbox_sha1sum       "b01b5835fa8ae7b7582968a7ecacb9b85503a6c9" ;
            foaf:name               "George V" ;
            foaf:nick               "jorch" ;
            foaf:phone              <tel:123456> ;
            foaf:schoolHomepage     <http://localhost:3030/Date/a school> ;
            foaf:title              "Dr" ;
            foaf:workInfoHomepage   <http://localhost:3030/Date/development> ;
            foaf:workplaceHomepage  <http://localhost:3030/Date/work> .
}

这是我的代码:

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import com.hp.hpl.jena.query.DatasetAccessor;
import com.hp.hpl.jena.query.DatasetAccessorFactory;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;

public class FusekiExample {

    public static void execSelectAndPrint(String serviceURI, String query) {
        QueryExecution q = QueryExecutionFactory.sparqlService(serviceURI,
                query);
        ResultSet results = q.execSelect();

        ResultSetFormatter.out(System.out, results);

        while (results.hasNext()) {
            QuerySolution soln = results.nextSolution();
            RDFNode x = soln.get("x");
            System.out.println(x);
        }
    }

    public static void execSelectAndProcess(String serviceURI, String query) {
        QueryExecution q = QueryExecutionFactory.sparqlService(serviceURI,
                query);
        ResultSet results = q.execSelect();

        while (results.hasNext()) {
            QuerySolution soln = results.nextSolution();
            // assumes that you have an "?x" in your query
            RDFNode x = soln.get("x");
            System.out.println(x);
        }

    }

    public static void main(String[] argv) throws IOException {
        execSelectAndPrint(
                "http://localhost:3030/Date/data/",
                "SELECT * WHERE { ?x  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  \"George V\" }");
        execSelectAndProcess(
                "http://localhost:3030/Date/data/" ,
                "SELECT * WHERE { ?x  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  \"George V\" }");  
    }
}

0 个答案:

没有答案