Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved Java to read rdf file

  • Loading branch information...
commit e14086aab6275455198a9ff0a9e66b0aec86f39c 1 parent 0c1545c
Rob Stewart authored
Showing with 4 additions and 6 deletions.
  1. +4 −6 slides.tex
View
10 slides.tex
@@ -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}
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.