openRDF.org Welcome Guest   | Login   
  Search  
  Index  | Recent Threads  | Who's Online  | User List  | Search  | Help  | RSS feeds

Forum has been closed down
This forum has been closed down due to extensive spamming activities. Please use the mailing list instead.


Quick Go »
Thread Status: Normal
Total posts in this thread: 2
[Add To My Favorites] [Watch this Thread]
Author
Previous Thread This topic has been viewed 1734 times and has 1 reply Next Thread
Aug 7, 2009 8:07:36 AM

jFeric
Visitor



Joined: Aug 7, 2009
Posts: 1
Status: Offline

How to determine the type of Value

First I get objects from statement with the type of Value. Because I just want to get Resource with URI, not those literals. Here I use type casting to test if there is exceptions. And I wonder any better solutions? Thanks for help!

RepositoryResult<Statement> statements = repositoryConnection.getStatements(null, null, null, false, (Resource)null);
HashSet<Value> terms = new HashSet<Value>();
while(statements.hasNext()) {
try {
Resource obj =(Resource) stmt.getObject();
terms.add(obj);
}
catch (ClassCastException e) {

}
}
Show Printable Version of Post        Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Aug 21, 2009 3:37:58 PM

james
OpenRDF.org Consultant
Member's Avatar

Canada
Joined: Jul 21, 2005
Posts: 650
Status: Offline
Re: How to determine the type of Value

use instanceof

RepositoryResult<Statement> statements = repositoryConnection.getStatements(null, null, null, false, (Resource)null);
HashSet<Value> terms = new HashSet<Value>();
while(statements.hasNext()) {
if (obj instanceof Resource) {
Resource obj =(Resource) stmt.getObject();
terms.add(obj);
}
}

----------------------------------------
Sesame Consultant
http://leighnet.ca
http://jamesrdf.blogspot.com
Show Printable Version of Post        Hidden to Guest    http://leighnet.ca [Link] Report threatening or abusive post: please login first  Go to top 
[Show Printable Version of Thread]