Difference between revisions of "Java Examples"

From Info216
m (Sinoa moved page Program examples to Examples)
Line 8: Line 8:
 
import org.apache.jena.rdf.model.ModelFactory;
 
import org.apache.jena.rdf.model.ModelFactory;
 
import org.apache.jena.rdf.model.Resource;
 
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDFS;
+
import org.apache.jena.vocabulary.FOAF;
  
 
public class HelloJena {
 
public class HelloJena {
Line 16: Line 16:
 
Model model = ModelFactory.createDefaultModel();
 
Model model = ModelFactory.createDefaultModel();
 
 
Resource andreas = model.createResource("http://example.org/andreas");
+
Resource andreas = model.createResource("http://no.uib.infomedia.info216.ex/CadeTracy");
andreas.addLiteral(RDFS.label, "Andreas Lothe Opdahl");
+
andreas.addLiteral(FOAF.name, "Cade Tracy");
 
 
 
model.write(System.out, "TURTLE");
 
model.write(System.out, "TURTLE");
 
 
}
 
}
 
}
 
}
 
  </nowiki>
 
  </nowiki>

Revision as of 18:11, 18 January 2017

Lecture 1

HelloJena.java

package no.uib.sinoa.info216;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.FOAF;

public class HelloJena {

	public static void main(String[] args) {
		
		Model model = ModelFactory.createDefaultModel();
		
		Resource andreas = model.createResource("http://no.uib.infomedia.info216.ex/CadeTracy");
		andreas.addLiteral(FOAF.name, "Cade Tracy");
		
		model.write(System.out, "TURTLE");
	}	
}