I started with this Andy,


public class MainActivity
{
private static MainActivity root = new MainActivity();
private static String baseUri = "";
 public static void main(String[] args)
{
String uri = "http://workingontologist.org/Examples/Chapter3/Product.n3";;
String uri2 = "http://dbpedia.org/page/Pizza";;

Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
 model = root.modelReadFile(root.getEntity(uri), model);
 StmtIterator sIterator =  model.listStatements();
 int lineCt = 0;
 while (sIterator.hasNext())
{
Statement s = sIterator.next();
System.out.println("Subject "+lineCt+++": "+s.getSubject().getLocalName());
}
}

private Model modelReadFile(String filename, Model model)
{
    try
    {
        File f = new File(filename);
        FileReader fr = new FileReader(f);
        model.read(fr, baseUri);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    if (model != null)
    {
     return model;
}
    return null;
}
 private String getEntity(String stringURI)
{
HttpGet get = new HttpGet();
get.setURI(URI.create(stringURI));
get.setHeader("Accept", "text/n3");
// get.setHeader("Accept", "application/rdf+xml");   // is this the correct
line for rdf/xml data?
HttpClient client = new DefaultHttpClient();
HttpResponse response = null;
 try {
response = client.execute(get);
}catch (ClientProtocolException e)
{
System.out.println("[ERROR] ClientProtocolException");
e.printStackTrace();
}catch (IOException e)
{
System.out.println("[ERROR] IOException");
e.printStackTrace();
}
 HttpEntity entity = response.getEntity();
 if (entity != null)
{
try {
return EntityUtils.toString(entity);
} catch (ParseException e)
{
System.out.println("[ERROR] ParseException");
e.printStackTrace();
} catch (IOException e)
{
System.out.println("[ERROR] IOException");
e.printStackTrace();
}
}
 return null;
}
}

Unfortunately, I am getting this exception

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.
java.io.FileNotFoundException: # Saved by TopBraid on Sun Feb 10 12:28:48
PST 2008
# baseURI: http:\www.workingontologist.org\Examples\Chapter3\Product.owl


On Mon, May 13, 2013 at 6:05 PM, Andy Seaborne <[email protected]> wrote:

> On 13/05/13 10:41, Joseph Daryl Locsin wrote:
>
>> How do you create a model of this strings using HTTP GET and/or POST?
>>
>> String uri = 
>> "http://workingontologist.org/**Examples/Chapter3/Product.n3<http://workingontologist.org/Examples/Chapter3/Product.n3>
>> ";
>> String uri2 = "http://dbpedia.org/page/Pizza**";;
>>
>> My project involves getting an external ontology and customizing it and
>> storing the custom ontology locally.
>>
>> The pseudocode is
>>
>> Create an HTTP GET or POST, add the string URL
>> Add appropriate Header info for handling N3, Turtle, RDF/XML
>> Read the file, return the String ontology
>> Create a model using the String ontology
>>
>> Thank you very much
>>
>>
> What have you tried?
>
> Your project seems to be about learning how HTTP content negotiation works
> for RDF data.  I suggest you use a tool like wget or curl to make the GET
> request to understand about setting up the HTTP request.
>
> Except they are bad examples:
>
> http://workingontologist.org/**Examples/Chapter3/Product.n3<http://workingontologist.org/Examples/Chapter3/Product.n3>
> always returns text/plain, whatever you ask for
>
> http://dbpedia.org/page/Pizza refuses to return N3, Turtle or RDF/XML
> (it's RDFa in XHTML only).
>
>         Andy
>
>


-- 
Regards,
Daryl

Reply via email to