You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by bocai <ji...@clas.ac.cn> on 2013/09/02 11:37:51 UTC

JENA API question

Hi,
I want to access remote sparql endpoint throuth JENA API. My program  is below.
After I ran the program, There is no record in resultset 
-----
| p |
=====
-----
But I visit http://dbpedia.org/sparql and ran this sparql ( select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as sparql in my program, I can get the result i want

p
http://dbpedia.org/resource/%C3%96lsen
http://dbpedia.org/resource/%C3%96stringen
http://dbpedia.org/resource/%C3%9Cbach-Palenberg
http://dbpedia.org/resource/%C3%9Cberherrn
http://dbpedia.org/resource/%C3%9Cdersdorf
http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
http://dbpedia.org/resource/%C3%9Crzig
http://dbpedia.org/resource/16_Blocks
http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
http://dbpedia.org/resource/2011_German_Grand_Prix


Can you point out my error? thanks very much!

public static void SearchSparql(){
  try {
   String queryStr = 
  "PREFIX dbpedia: <http://dbpedia.org/>" +
  "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
  "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";

            Query query = QueryFactory.create(queryStr);
            QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
            ((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
            ResultSet rs = qexec.execSelect();
            ResultSetFormatter.out(System.out, rs, query);
            qexec.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

 }


2013-09-02 bocai  
中国科学院国家科学图书馆成都分馆 中国科学院成都文献情报中心
联系电话:028-85220240
联系地址:610041 四川省成都市一环路南二段16号
电子邮箱:jiangeb@clas.ac.cn
----------------------------------------------------------------------

Re: JENA API question

Posted by Dave Reynolds <da...@gmail.com>.
On 02/09/13 10:37, bocai wrote:
> Hi,
> I want to access remote sparql endpoint throuth JENA API. My program  is below.
> After I ran the program, There is no record in resultset
> -----
> | p |
> =====
> -----
> But I visit http://dbpedia.org/sparql and ran this sparql ( select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as sparql in my program, I can get the result i want
> 
> p
> http://dbpedia.org/resource/%C3%96lsen
> http://dbpedia.org/resource/%C3%96stringen
> http://dbpedia.org/resource/%C3%9Cbach-Palenberg
> http://dbpedia.org/resource/%C3%9Cberherrn
> http://dbpedia.org/resource/%C3%9Cdersdorf
> http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
> http://dbpedia.org/resource/%C3%9Crzig
> http://dbpedia.org/resource/16_Blocks
> http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
> http://dbpedia.org/resource/2011_German_Grand_Prix
> 
> 
> Can you point out my error? thanks very much!
> 
> public static void SearchSparql(){
>    try {
>     String queryStr =
>    "PREFIX dbpedia: <http://dbpedia.org/>" +
>    "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
>    "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";

If I run that query using the SPARQL form at http://dbpedia.org/sparql I
also get an empty result.

Looking at the data then I suspect the problem is your dbpedia prefix,
correct it to:

PREFIX dbpedia: <http://dbpedia.org/resource/>

Dave


Re: Re: JENA API question

Posted by Marco Neumann <ma...@gmail.com>.
It apparently worked for you. I consider this thread closed.

http://sourceforge.net/mailarchive/forum.php?thread_name=201309031713122810608%40clas.ac.cn&forum_name=dbpedia-discussion


On Tue, Sep 3, 2013 at 4:57 AM, bocai <ji...@clas.ac.cn> wrote:

> Of course I can access the sparql endpoint at http://dbpedia.org/sparqlfrom my jvm.
> I think the error has relation with PREFIX.
>
> when I access with
>       "SELECT DISTINCT ?company where {?company a <
> http://dbpedia.org/ontology/Company>} LIMIT 20";
> I can get result. But when I access with
>    "PREFIX dbpedia: <http://dbpedia.org/resource/> " +
>    "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> " +
>    "select ?p where {?p dbpedia-owl:country dbpedia:Germany> .} LIMIT 10";
> there is not result
>
> log4j:WARN No appenders could be found for logger
> (com.hp.hpl.jena.util.FileManager).
> log4j:WARN Please initialize the log4j system properly.
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
> more info.
> ----------------------------------------------------------------
> | company                                                      |
> ================================================================
> | <http://dbpedia.org/resource/%C3%9Cstra>                     |
> | <http://dbpedia.org/resource/%C4%8Cesk%C3%A9_dr%C3%A1hy>     |
> | <http://dbpedia.org/resource/7th_Level>                      |
> | <http://dbpedia.org/resource/A&W_Restaurants>                |
> | <http://dbpedia.org/resource/A._Lange_&_S%C3%B6hne>          |
> | <http://dbpedia.org/resource/ABB_Group>                      |
> | <http://dbpedia.org/resource/ABC_Motors>                     |
> | <http://dbpedia.org/resource/AG_Vulcan_Stettin>              |
> | <http://dbpedia.org/resource/AIDA_Cruises>                   |
> | <http://dbpedia.org/resource/AM_General>                     |
> | <http://dbpedia.org/resource/ARY_Group>                      |
> | <http://dbpedia.org/resource/AVG_Technologies>               |
> | <http://dbpedia.org/resource/Abbott-Detroit>                 |
> | <http://dbpedia.org/resource/Accenture>                      |
> | <http://dbpedia.org/resource/Adnams_Brewery>                 |
> | <http://dbpedia.org/resource/Aer_Arann>                      |
> | <http://dbpedia.org/resource/Aero_Lloyd>                     |
> | <http://dbpedia.org/resource/Aeropostal_Alas_de_Venezuela>   |
> | <http://dbpedia.org/resource/Afrinat_International_Airlines> |
> | <http://dbpedia.org/resource/Afriqiyah_Airways>              |
> ----------------------------------------------------------------
>
>
>
>
>
>
> ----------------------------------------------------------------------
>
> 发件人: Marco Neumann
> 发送时间: 2013-09-03 15:04
> 收件人: users
> 主题: Re: Re: JENA API question
> make sure you can access the sparql endpoint at
> http://dbpedia.org/sparqlfrom your
> jvm.
>
> QueryExecution qexec = QueryExecutionFactory.sparqlService("
> http://dbpedia.org/sparql", query);
>
>
>
> On Mon, Sep 2, 2013 at 9:42 PM, bocai <ji...@clas.ac.cn> wrote:
>
> > Oh, I changed Prefix from
> > "PREFIX dbpedia: http://dbpedia.org/"
> > to
> > "PREFIX dbpedia: <http://dbpedia.org/resource/>"
> >
> > the error also changed as below:
> > HttpException: java.net.SocketException: Connection reset:
> > java.net.SocketException: Connection reset
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:529)
> > at
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:289)
> > at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:240)
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:302)
> > at Dbpedia.GetFromSparql.SearchSparql(GetFromSparql.java:42)
> > at Dbpedia.GetFromSparql.main(GetFromSparql.java:53)
> >
> > Caused by: java.net.SocketException: Connection reset
> > at java.net.SocketInputStream.read(SocketInputStream.java:168)
> > at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
> > at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
> > at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
> > at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
> > at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
> > at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:652)
> > at
> >
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
> > at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:412)
> > ... 5 more
> >
> > How can I do ?
> >
> >
> >
> > 发件人: Marco Neumann
> > 发送时间: 2013-09-02 18:46
> > 收件人: users
> > 主题: Re: JENA API question
> > change dbpedia prefix to
> >
> >   "PREFIX dbpedia: <http://dbpedia.org/resource/>" +
> >
> >
> > On Mon, Sep 2, 2013 at 5:37 AM, bocai <ji...@clas.ac.cn> wrote:
> >
> > > Hi,
> > > I want to access remote sparql endpoint throuth JENA API. My program
>  is
> > > below.
> > > After I ran the program, There is no record in resultset
> > > -----
> > > | p |
> > > =====
> > > -----
> > > But I visit http://dbpedia.org/sparql and ran this sparql ( select *
> > > where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as
> > > sparql in my program, I can get the result i want
> > >
> > > p
> > > http://dbpedia.org/resource/%C3%96lsen
> > > http://dbpedia.org/resource/%C3%96stringen
> > > http://dbpedia.org/resource/%C3%9Cbach-Palenberg
> > > http://dbpedia.org/resource/%C3%9Cberherrn
> > > http://dbpedia.org/resource/%C3%9Cdersdorf
> > > http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
> > > http://dbpedia.org/resource/%C3%9Crzig
> > > http://dbpedia.org/resource/16_Blocks
> > > http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
> > > http://dbpedia.org/resource/2011_German_Grand_Prix
> > >
> > >
> > > Can you point out my error? thanks very much!
> > >
> > > public static void SearchSparql(){
> > >   try {
> > >    String queryStr =
> > >   "PREFIX dbpedia: <http://dbpedia.org/>" +
> > >   "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
> > >   "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";
> > >
> > >             Query query = QueryFactory.create(queryStr);
> > >             QueryExecution qexec =
> QueryExecutionFactory.sparqlService("
> > > http://dbpedia.org/sparql", query);
> > >             ((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
> > >             ResultSet rs = qexec.execSelect();
> > >             ResultSetFormatter.out(System.out, rs, query);
> > >             qexec.close();
> > >         } catch (Exception e) {
> > >             e.printStackTrace();
> > >         }
> > >
> > >  }
> > >
> > >
> > > -
> >
> >
> > ---
> > Marco Neumann
> > KONA
>
>
>
>
> --
>
>
> ---
> Marco Neumann
> KONA
>



-- 


---
Marco Neumann
KONA

Re: 回复: Re: JENA API question

Posted by Andy Seaborne <an...@apache.org>.
On 03/09/13 09:57, bocai wrote:
> Of course I can access the sparql endpoint at http://dbpedia.org/sparql from my jvm.
> I think the error has relation with PREFIX.

It's a networking issue:

[[
HttpException: java.net.SocketException: Connection reset:

Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
]]

whether that is DBpedia deciding to terminate the request, some
intermediary blocking access or something else, we can't tell.

It works for me from here.

You don't need to set any params.

	Andy


回复: Re: JENA API question

Posted by bocai <ji...@clas.ac.cn>.
Of course I can access the sparql endpoint at http://dbpedia.org/sparql from my jvm.
I think the error has relation with PREFIX. 

when I access with 
      "SELECT DISTINCT ?company where {?company a <http://dbpedia.org/ontology/Company>} LIMIT 20";
I can get result. But when I access with  
   "PREFIX dbpedia: <http://dbpedia.org/resource/> " +
   "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> " +
   "select ?p where {?p dbpedia-owl:country dbpedia:Germany> .} LIMIT 10";
there is not result

log4j:WARN No appenders could be found for logger (com.hp.hpl.jena.util.FileManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
----------------------------------------------------------------
| company                                                      |
================================================================
| <http://dbpedia.org/resource/%C3%9Cstra>                     |
| <http://dbpedia.org/resource/%C4%8Cesk%C3%A9_dr%C3%A1hy>     |
| <http://dbpedia.org/resource/7th_Level>                      |
| <http://dbpedia.org/resource/A&W_Restaurants>                |
| <http://dbpedia.org/resource/A._Lange_&_S%C3%B6hne>          |
| <http://dbpedia.org/resource/ABB_Group>                      |
| <http://dbpedia.org/resource/ABC_Motors>                     |
| <http://dbpedia.org/resource/AG_Vulcan_Stettin>              |
| <http://dbpedia.org/resource/AIDA_Cruises>                   |
| <http://dbpedia.org/resource/AM_General>                     |
| <http://dbpedia.org/resource/ARY_Group>                      |
| <http://dbpedia.org/resource/AVG_Technologies>               |
| <http://dbpedia.org/resource/Abbott-Detroit>                 |
| <http://dbpedia.org/resource/Accenture>                      |
| <http://dbpedia.org/resource/Adnams_Brewery>                 |
| <http://dbpedia.org/resource/Aer_Arann>                      |
| <http://dbpedia.org/resource/Aero_Lloyd>                     |
| <http://dbpedia.org/resource/Aeropostal_Alas_de_Venezuela>   |
| <http://dbpedia.org/resource/Afrinat_International_Airlines> |
| <http://dbpedia.org/resource/Afriqiyah_Airways>              |
----------------------------------------------------------------






----------------------------------------------------------------------

发件人: Marco Neumann
发送时间: 2013-09-03 15:04
收件人: users
主题: Re: Re: JENA API question
make sure you can access the sparql endpoint at
http://dbpedia.org/sparqlfrom your
jvm.

QueryExecution qexec = QueryExecutionFactory.sparqlService("
http://dbpedia.org/sparql", query);



On Mon, Sep 2, 2013 at 9:42 PM, bocai <ji...@clas.ac.cn> wrote:

> Oh, I changed Prefix from
> "PREFIX dbpedia: http://dbpedia.org/"
> to
> "PREFIX dbpedia: <http://dbpedia.org/resource/>"
>
> the error also changed as below:
> HttpException: java.net.SocketException: Connection reset:
> java.net.SocketException: Connection reset
> at
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:529)
> at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:289)
> at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:240)
> at
> com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:302)
> at Dbpedia.GetFromSparql.SearchSparql(GetFromSparql.java:42)
> at Dbpedia.GetFromSparql.main(GetFromSparql.java:53)
>
> Caused by: java.net.SocketException: Connection reset
> at java.net.SocketInputStream.read(SocketInputStream.java:168)
> at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
> at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:652)
> at
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
> at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
> at
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:412)
> ... 5 more
>
> How can I do ?
>
>
>
> 发件人: Marco Neumann
> 发送时间: 2013-09-02 18:46
> 收件人: users
> 主题: Re: JENA API question
> change dbpedia prefix to
>
>   "PREFIX dbpedia: <http://dbpedia.org/resource/>" +
>
>
> On Mon, Sep 2, 2013 at 5:37 AM, bocai <ji...@clas.ac.cn> wrote:
>
> > Hi,
> > I want to access remote sparql endpoint throuth JENA API. My program  is
> > below.
> > After I ran the program, There is no record in resultset
> > -----
> > | p |
> > =====
> > -----
> > But I visit http://dbpedia.org/sparql and ran this sparql ( select *
> > where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as
> > sparql in my program, I can get the result i want
> >
> > p
> > http://dbpedia.org/resource/%C3%96lsen
> > http://dbpedia.org/resource/%C3%96stringen
> > http://dbpedia.org/resource/%C3%9Cbach-Palenberg
> > http://dbpedia.org/resource/%C3%9Cberherrn
> > http://dbpedia.org/resource/%C3%9Cdersdorf
> > http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
> > http://dbpedia.org/resource/%C3%9Crzig
> > http://dbpedia.org/resource/16_Blocks
> > http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
> > http://dbpedia.org/resource/2011_German_Grand_Prix
> >
> >
> > Can you point out my error? thanks very much!
> >
> > public static void SearchSparql(){
> >   try {
> >    String queryStr =
> >   "PREFIX dbpedia: <http://dbpedia.org/>" +
> >   "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
> >   "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";
> >
> >             Query query = QueryFactory.create(queryStr);
> >             QueryExecution qexec = QueryExecutionFactory.sparqlService("
> > http://dbpedia.org/sparql", query);
> >             ((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
> >             ResultSet rs = qexec.execSelect();
> >             ResultSetFormatter.out(System.out, rs, query);
> >             qexec.close();
> >         } catch (Exception e) {
> >             e.printStackTrace();
> >         }
> >
> >  }
> >
> >
> > -
>
>
> ---
> Marco Neumann
> KONA




-- 


---
Marco Neumann
KONA

Re: Re: JENA API question

Posted by Olivier Rossel <ol...@gmail.com>.
Might be a good idea to check the proxy settings of your JVM (if a proxy is
managing your web connection).
This code should do the trick:

System.setProperty("http.proxyHost", yourProxy);
System.setProperty("http.proxyPort", yourproxyPort)

final String authUser = "yourUser";
final String authPassword = "yourPassword";
Authenticator.setDefault(
   new Authenticator() {
      public PasswordAuthentication getPasswordAuthentication() {
         return new PasswordAuthentication(
               authUser, authPassword.toCharArray());
      }
   }
);

System.setProperty("http.proxyUser", authUser);
System.setProperty("http.proxyPassword", authPassword);




On Tue, Sep 3, 2013 at 9:04 AM, Marco Neumann <ma...@gmail.com>wrote:

> make sure you can access the sparql endpoint at
> http://dbpedia.org/sparqlfrom your
> jvm.
>
> QueryExecution qexec = QueryExecutionFactory.sparqlService("
> http://dbpedia.org/sparql", query);
>
>
>
> On Mon, Sep 2, 2013 at 9:42 PM, bocai <ji...@clas.ac.cn> wrote:
>
> > Oh, I changed Prefix from
> > "PREFIX dbpedia: http://dbpedia.org/"
> > to
> > "PREFIX dbpedia: <http://dbpedia.org/resource/>"
> >
> > the error also changed as below:
> > HttpException: java.net.SocketException: Connection reset:
> > java.net.SocketException: Connection reset
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:529)
> > at
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:289)
> > at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:240)
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:302)
> > at Dbpedia.GetFromSparql.SearchSparql(GetFromSparql.java:42)
> > at Dbpedia.GetFromSparql.main(GetFromSparql.java:53)
> >
> > Caused by: java.net.SocketException: Connection reset
> > at java.net.SocketInputStream.read(SocketInputStream.java:168)
> > at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
> > at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
> > at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
> > at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
> > at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
> > at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:652)
> > at
> >
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
> > at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:412)
> > ... 5 more
> >
> > How can I do ?
> >
> >
> >
> > 发件人: Marco Neumann
> > 发送时间: 2013-09-02 18:46
> > 收件人: users
> > 主题: Re: JENA API question
> > change dbpedia prefix to
> >
> >   "PREFIX dbpedia: <http://dbpedia.org/resource/>" +
> >
> >
> > On Mon, Sep 2, 2013 at 5:37 AM, bocai <ji...@clas.ac.cn> wrote:
> >
> > > Hi,
> > > I want to access remote sparql endpoint throuth JENA API. My program
>  is
> > > below.
> > > After I ran the program, There is no record in resultset
> > > -----
> > > | p |
> > > =====
> > > -----
> > > But I visit http://dbpedia.org/sparql and ran this sparql ( select *
> > > where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as
> > > sparql in my program, I can get the result i want
> > >
> > > p
> > > http://dbpedia.org/resource/%C3%96lsen
> > > http://dbpedia.org/resource/%C3%96stringen
> > > http://dbpedia.org/resource/%C3%9Cbach-Palenberg
> > > http://dbpedia.org/resource/%C3%9Cberherrn
> > > http://dbpedia.org/resource/%C3%9Cdersdorf
> > > http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
> > > http://dbpedia.org/resource/%C3%9Crzig
> > > http://dbpedia.org/resource/16_Blocks
> > > http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
> > > http://dbpedia.org/resource/2011_German_Grand_Prix
> > >
> > >
> > > Can you point out my error? thanks very much!
> > >
> > > public static void SearchSparql(){
> > >   try {
> > >    String queryStr =
> > >   "PREFIX dbpedia: <http://dbpedia.org/>" +
> > >   "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
> > >   "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";
> > >
> > >             Query query = QueryFactory.create(queryStr);
> > >             QueryExecution qexec =
> QueryExecutionFactory.sparqlService("
> > > http://dbpedia.org/sparql", query);
> > >             ((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
> > >             ResultSet rs = qexec.execSelect();
> > >             ResultSetFormatter.out(System.out, rs, query);
> > >             qexec.close();
> > >         } catch (Exception e) {
> > >             e.printStackTrace();
> > >         }
> > >
> > >  }
> > >
> > >
> > > -
> >
> >
> > ---
> > Marco Neumann
> > KONA
>
>
>
>
> --
>
>
> ---
> Marco Neumann
> KONA
>

Re: Re: JENA API question

Posted by Marco Neumann <ma...@gmail.com>.
make sure you can access the sparql endpoint at
http://dbpedia.org/sparqlfrom your
jvm.

QueryExecution qexec = QueryExecutionFactory.sparqlService("
http://dbpedia.org/sparql", query);



On Mon, Sep 2, 2013 at 9:42 PM, bocai <ji...@clas.ac.cn> wrote:

> Oh, I changed Prefix from
> "PREFIX dbpedia: http://dbpedia.org/"
> to
> "PREFIX dbpedia: <http://dbpedia.org/resource/>"
>
> the error also changed as below:
> HttpException: java.net.SocketException: Connection reset:
> java.net.SocketException: Connection reset
> at
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:529)
> at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:289)
> at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:240)
> at
> com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:302)
> at Dbpedia.GetFromSparql.SearchSparql(GetFromSparql.java:42)
> at Dbpedia.GetFromSparql.main(GetFromSparql.java:53)
>
> Caused by: java.net.SocketException: Connection reset
> at java.net.SocketInputStream.read(SocketInputStream.java:168)
> at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
> at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:652)
> at
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
> at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
> at
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:412)
> ... 5 more
>
> How can I do ?
>
>
>
> 发件人: Marco Neumann
> 发送时间: 2013-09-02 18:46
> 收件人: users
> 主题: Re: JENA API question
> change dbpedia prefix to
>
>   "PREFIX dbpedia: <http://dbpedia.org/resource/>" +
>
>
> On Mon, Sep 2, 2013 at 5:37 AM, bocai <ji...@clas.ac.cn> wrote:
>
> > Hi,
> > I want to access remote sparql endpoint throuth JENA API. My program  is
> > below.
> > After I ran the program, There is no record in resultset
> > -----
> > | p |
> > =====
> > -----
> > But I visit http://dbpedia.org/sparql and ran this sparql ( select *
> > where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as
> > sparql in my program, I can get the result i want
> >
> > p
> > http://dbpedia.org/resource/%C3%96lsen
> > http://dbpedia.org/resource/%C3%96stringen
> > http://dbpedia.org/resource/%C3%9Cbach-Palenberg
> > http://dbpedia.org/resource/%C3%9Cberherrn
> > http://dbpedia.org/resource/%C3%9Cdersdorf
> > http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
> > http://dbpedia.org/resource/%C3%9Crzig
> > http://dbpedia.org/resource/16_Blocks
> > http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
> > http://dbpedia.org/resource/2011_German_Grand_Prix
> >
> >
> > Can you point out my error? thanks very much!
> >
> > public static void SearchSparql(){
> >   try {
> >    String queryStr =
> >   "PREFIX dbpedia: <http://dbpedia.org/>" +
> >   "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
> >   "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";
> >
> >             Query query = QueryFactory.create(queryStr);
> >             QueryExecution qexec = QueryExecutionFactory.sparqlService("
> > http://dbpedia.org/sparql", query);
> >             ((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
> >             ResultSet rs = qexec.execSelect();
> >             ResultSetFormatter.out(System.out, rs, query);
> >             qexec.close();
> >         } catch (Exception e) {
> >             e.printStackTrace();
> >         }
> >
> >  }
> >
> >
> > -
>
>
> ---
> Marco Neumann
> KONA




-- 


---
Marco Neumann
KONA

回复: Re: JENA API question

Posted by bocai <ji...@clas.ac.cn>.
Oh, I changed Prefix from 
"PREFIX dbpedia: http://dbpedia.org/" 
to 
"PREFIX dbpedia: <http://dbpedia.org/resource/>" 

the error also changed as below:
HttpException: java.net.SocketException: Connection reset: java.net.SocketException: Connection reset
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:529)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:289)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:240)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:302)
at Dbpedia.GetFromSparql.SearchSparql(GetFromSparql.java:42)
at Dbpedia.GetFromSparql.main(GetFromSparql.java:53)

Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:652)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:412)
... 5 more

How can I do ?



发件人: Marco Neumann
发送时间: 2013-09-02 18:46
收件人: users
主题: Re: JENA API question
change dbpedia prefix to

  "PREFIX dbpedia: <http://dbpedia.org/resource/>" +


On Mon, Sep 2, 2013 at 5:37 AM, bocai <ji...@clas.ac.cn> wrote:

> Hi,
> I want to access remote sparql endpoint throuth JENA API. My program  is
> below.
> After I ran the program, There is no record in resultset
> -----
> | p |
> =====
> -----
> But I visit http://dbpedia.org/sparql and ran this sparql ( select *
> where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as
> sparql in my program, I can get the result i want
>
> p
> http://dbpedia.org/resource/%C3%96lsen
> http://dbpedia.org/resource/%C3%96stringen
> http://dbpedia.org/resource/%C3%9Cbach-Palenberg
> http://dbpedia.org/resource/%C3%9Cberherrn
> http://dbpedia.org/resource/%C3%9Cdersdorf
> http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
> http://dbpedia.org/resource/%C3%9Crzig
> http://dbpedia.org/resource/16_Blocks
> http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
> http://dbpedia.org/resource/2011_German_Grand_Prix
>
>
> Can you point out my error? thanks very much!
>
> public static void SearchSparql(){
>   try {
>    String queryStr =
>   "PREFIX dbpedia: <http://dbpedia.org/>" +
>   "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
>   "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";
>
>             Query query = QueryFactory.create(queryStr);
>             QueryExecution qexec = QueryExecutionFactory.sparqlService("
> http://dbpedia.org/sparql", query);
>             ((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
>             ResultSet rs = qexec.execSelect();
>             ResultSetFormatter.out(System.out, rs, query);
>             qexec.close();
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>
>  }
>
>
> - 


---
Marco Neumann
KONA

Re: JENA API question

Posted by Marco Neumann <ma...@gmail.com>.
change dbpedia prefix to

  "PREFIX dbpedia: <http://dbpedia.org/resource/>" +


On Mon, Sep 2, 2013 at 5:37 AM, bocai <ji...@clas.ac.cn> wrote:

> Hi,
> I want to access remote sparql endpoint throuth JENA API. My program  is
> below.
> After I ran the program, There is no record in resultset
> -----
> | p |
> =====
> -----
> But I visit http://dbpedia.org/sparql and ran this sparql ( select *
> where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as
> sparql in my program, I can get the result i want
>
> p
> http://dbpedia.org/resource/%C3%96lsen
> http://dbpedia.org/resource/%C3%96stringen
> http://dbpedia.org/resource/%C3%9Cbach-Palenberg
> http://dbpedia.org/resource/%C3%9Cberherrn
> http://dbpedia.org/resource/%C3%9Cdersdorf
> http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
> http://dbpedia.org/resource/%C3%9Crzig
> http://dbpedia.org/resource/16_Blocks
> http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
> http://dbpedia.org/resource/2011_German_Grand_Prix
>
>
> Can you point out my error? thanks very much!
>
> public static void SearchSparql(){
>   try {
>    String queryStr =
>   "PREFIX dbpedia: <http://dbpedia.org/>" +
>   "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
>   "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";
>
>             Query query = QueryFactory.create(queryStr);
>             QueryExecution qexec = QueryExecutionFactory.sparqlService("
> http://dbpedia.org/sparql", query);
>             ((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
>             ResultSet rs = qexec.execSelect();
>             ResultSetFormatter.out(System.out, rs, query);
>             qexec.close();
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>
>  }
>
>
> 2013-09-02 bocai
> 中国科学院国家科学图书馆成都分馆 中国科学院成都文献情报中心
> 联系电话:028-85220240
> 联系地址:610041 四川省成都市一环路南二段16号
> 电子邮箱:jiangeb@clas.ac.cn
> ----------------------------------------------------------------------




-- 


---
Marco Neumann
KONA