You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@any23.apache.org by "Meraj A. Khan" <me...@gmail.com> on 2015/01/16 18:06:35 UTC
Extract a Open Graph value from a web page
Hi All,
I am trying to retrieve an object value as in subject-predicate-object
from a web page and using the following code , the page I am
extracting it from is
http://www.macmall.com/p/Apple-Mac-Mini/product~dpno~13312163~pdp.ijcehjd
as you can clearly see it has og markup using RDFa , however the below
code fails to extract any og values , can you please let me know
what I might be doing wrong, the property Name that I am trying to
extract is OGP.imageUrl
Thanks.
private static String retrieveOGPProperty(String URL,String propertyName) {
logger.trace("Entering the method retrieveOGPProperty ");
String propertyValue = null;
OGP ogp = OGP.getInstance();
org.openrdf.sail.Sail store = new org.openrdf.sail.memory.MemoryStore();
try {
store.initialize();
} catch (SailException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
org.openrdf.repository.RepositoryConnection conn = new
org.openrdf.repository.sail.SailRepository(store).getConnection();
RepositoryResult<org.openrdf.model.Statement> statements =
conn.getStatements(RDFUtils.uri(URL), ogp.imageURL, null,false);
if(statements.hasNext()){
//get the first property
Value object = statements.next().getObject();
propertyValue = object.stringValue();
}
} catch (RepositoryException e) {
// Log the error and ignore it
logger.error("Error occured while extracting the OGP property "+propertyName,e);
}
logger.trace("Exiting the method retrieveOGPProperty ");
return propertyValue;
}