Skip to content

Commit

Permalink
Improved Java to read rdf file
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Stewart committed Apr 19, 2012
1 parent 0c1545c commit e14086a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions slides.tex
Expand Up @@ -930,12 +930,8 @@ \section{Semantic Web Toolkits}
\textbf{Java}

\begin{lstlisting}[style=MyJavaStyle]
final public void readFile(String filename) throws FileNotFoundException {
Model model = ModelFactory.createDefaultModel();
String str = new Scanner(new File("file.rdf")).useDelimiter("Z").next();
InputStream is = new ByteArrayInputStream(str.getBytes());
BufferedReader br = new BufferedReader(new InputStreamReader(is));
model.read(br, null);
final public Model readFile(String filename) throws FileNotFoundException {
return ModelFactory.createDefaultModel().read(new FileReader("file.rdf"), null);
}
\end{lstlisting}

Expand Down Expand Up @@ -1059,10 +1055,12 @@ \section{Semantic Web Toolkits}
model.setNsPrefix("foaf", foafNS);
Property topic_interest = model.createProperty(foafNS, "topic_interest");
Property account = model.createProperty(foafNS, "account");

Resource me = model.createResource("http://example.org/users/robstewart");
Resource twitter = model.createResource("https://twitter.com/#!/robstewartUK");
Resource haskell = model.createResource(
"http://dbpedia.org/resource/Haskell_(programming_language)");

Statement stmt;
stmt = model.createStatement(me, account, twitter);
model.add(stmt);
Expand Down

0 comments on commit e14086a

Please sign in to comment.