當前位置: 首頁>>代碼示例>>Java>>正文


Java OntModel.write方法代碼示例

本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.write方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.write方法的具體用法?Java OntModel.write怎麽用?Java OntModel.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.hp.hpl.jena.ontology.OntModel的用法示例。


在下文中一共展示了OntModel.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: printResults

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * Prints the actual knowledge with the actual execution number and what new statements are created with
 * ruleEngine
 *
 *
 * @param pOntology: The actual knowledge ( Base + inferred)
 * @param pInf: The list containing the inferred elements.
 */
private void printResults(OntModel pOntology, InfModel pInf, Model pInstances) {
    this.execution++;
    pOntology.write(System.out, "N-TRIPLES");
    System.out.println("========================================");
    System.out.println("Number of elements: "+ pInstances.size());
    System.out.println("Execution number :"+this.execution);
    System.out.println("Infered count list "+pInf.getDeductionsModel().size());
}
 
開發者ID:aitoralmeida,項目名稱:c4a_data_repository,代碼行數:17,代碼來源:RuleEngine.java

示例2: createJenaModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void createJenaModel(RegisterContextRequest rcr) {

        OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
        Model entityOnt = FileManager.get().loadModel(ONT_FILE);
        ontModel.addSubModel(entityOnt);
        ontModel.setNsPrefixes(entityOnt.getNsPrefixMap());

//         OntClass regClass = ontModel.getOntClass(ONT_URL + "iotReg");
//         OntClass entClass = ontModel.createOntClass(ONT_URL + "entity");
//        OntClass regClass = (OntClass) ontModel.createOntResource(OntClass.class, null,ONT_URL+"Registration" );
//        OntClass regClass = (OntClass) ontModel.createClass(ONT_URL + "Registration");
//        OntClass entityClass = (OntClass) ontModel.createClass(ONT_URL + "Entity");
        OntClass entityClass = (OntClass) ontModel.getOntClass(ONT_URL + "Entity");

//         System.out.println("Class type is: " + regClass.getLocalName());
//         System.out.println(rcr.getRegistrationId());
        Individual regIndividual = ontModel.createIndividual(ONT_URL + "roomSensor13CII01", entityClass);
        
        System.out.println("has propertry \"expiry\":"+regIndividual.hasProperty(ontModel.getProperty(ONT_URL, "expiry")));
//        Property p = ontModel.createProperty(ONT_URL, "hasRegistrationId");
//        regIndividual.addProperty(p, "");
        regIndividual.setPropertyValue(ontModel.getProperty(ONT_URL, "registrationId"), ontModel.createLiteral(rcr.getRegistrationId()));
//        p = ontModel.createProperty(ONT_URL, "hasDuration");
//        regIndividual.addProperty(p, "");
        regIndividual.setPropertyValue(ontModel.getProperty(ONT_URL, "expiry"), ontModel.createLiteral(rcr.getDuration()));
        System.out.println("has propertry \"expiry\":"+regIndividual.hasProperty(ontModel.getProperty(ONT_URL, "expiry")));

        ExtendedIterator<OntProperty> iter = ontModel.listAllOntProperties();
        while (iter.hasNext()) {
            OntProperty ontProp = iter.next();
            System.out.println(ontProp.getLocalName());
//            if (formParams.containsKey(ontProp.getLocalName())) {
//                regIndividual.addProperty(ontProp, ontModel.getcreateTypedLiteral(formParams.get(ontProp.getLocalName())[0]));
//            }
        }
        ontModel.write(System.out, "TURTLE");
//        ontModel.write(System.out, "RDF/XML");
//          ontModel.write(System.out, "JSON-LD");

    }
 
開發者ID:UniSurreyIoT,項目名稱:fiware-iot-discovery-ngsi9,代碼行數:41,代碼來源:SemanticConverter.java

示例3: saveModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void saveModel(OntModel model, String path) throws IOException {

		File file = new File(path);
		file.createNewFile();
		FileOutputStream fos = new FileOutputStream(file, false);
		OutputStreamWriter writer = new OutputStreamWriter(fos, "UTF-8");
		model.write(writer, "N-TRIPLES");
	}
 
開發者ID:sll-mdilab,項目名稱:t5-doc,代碼行數:9,代碼來源:CSVSToRDFConverter.java

示例4: writeSemanticModelFiles

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
	 * Uses the classes from the DB to write the RDF files based on those.
	 */
	public static void writeSemanticModelFiles() {
		logger.debug("Writing the context model to a file");

		// TODO: Complement the model with the other required entities 
		OntModel usersModel = writeUserEntries();
		OntModel projectsModel = writeProjectEntries();
		OntModel metadataModel = writeMetaDataModelEntries();

		//	uqModel.write(System.out, "RDF/XML");
		//	RDFDataMgr.write(System.out, uqModel, RDFFormat.RDFXML_PRETTY);

		// Write the individual models to a single file
		// holding all the triples
		final OntModel combined = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
		for (final OntModel part : new OntModel[] { usersModel, projectsModel, metadataModel } ) {
			combined.add(part);
		}
		try {
			String dataDir = UQasarUtil.getDataDirPath();
			// TODO: Find out why this does not work in Linux
//			String modelPath = "file:///" + dataDir + ONTOLOGYFILE;
			String modelPath = dataDir + ONTOLOGYFILE;
			
			combined.write(new FileOutputStream(modelPath, false));
			logger.debug("Context Model written to file " +modelPath);
			UQasarUtil.setUqModel(combined);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
開發者ID:U-QASAR,項目名稱:u-qasar.platform,代碼行數:34,代碼來源:UQasarUtil.java

示例5: Build

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void Build(String path) throws IOException {
		
		List<HNode> sortedLeafHNodes = new ArrayList<HNode>();
		worksheet.getHeaders().getSortedLeafHNodes(sortedLeafHNodes);
		OntModel autoOntology = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
		String ns = Namespaces.KARMA;
		autoOntology.setNsPrefix("karma", ns);
		OntClass topClass = autoOntology.createClass( ns + worksheet.getTitle().replaceAll(" ", "_")); // replace blank spaces with undrscore
		for (HNode hNode : sortedLeafHNodes){
			DatatypeProperty dp = autoOntology.createDatatypeProperty(ns+hNode.getColumnName().trim().replaceAll(" ", "_"));
			dp.addDomain(topClass);
			dp.addRange(XSD.xstring);
		}
		
//		OntClass thingClass = autoOntology.createClass(Uris.THING_URI);
		ObjectProperty op = autoOntology.createObjectProperty(ns + "relatedTo");
		op.addDomain(topClass);
//		op.addRange(thingClass);
		
		Writer outUTF8 =null;
		try {
			outUTF8 = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream(path), "UTF8"));
			autoOntology.write(outUTF8, null);
			outUTF8.flush();
			outUTF8.close();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
 
開發者ID:therelaxist,項目名稱:spring-usc,代碼行數:31,代碼來源:AutoOntology.java

示例6: doTestDatatypeRangeValidation

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private void doTestDatatypeRangeValidation(RDFDatatype over12Type, OntModelSpec spec) {	
		OntModel ont = ModelFactory.createOntologyModel(spec);
		String NS = "http://jena.hpl.hp.com/example#";
	    Resource over12 = ont.createResource( over12Type.getURI() );
	    DatatypeProperty hasValue = ont.createDatatypeProperty(NS + "hasValue");
	    hasValue.addRange( over12 );
	    
	    ont.createResource(NS + "a").addProperty(hasValue, "15", over12Type);
	    ont.createResource(NS + "b").addProperty(hasValue, "16", over12Type);
	    ont.createResource(NS + "c").addProperty(hasValue, "10", over12Type);
	    
	    ValidityReport validity = ont.validate();
	    assertTrue (! validity.isValid()); 
	    Iterator<Report> ritr = validity.getReports();
	    while (ritr.hasNext()) {
	    	System.out.println("For spec '" + spec + "': " + ritr.next().toString());
	    }
	    ont.write(System.out);
	    
	    // Check culprit reporting
	    ValidityReport.Report report = (validity.getReports().next());
	    Triple culprit = (Triple)report.getExtension();
	    assertEquals(culprit.getSubject().getURI(), NS + "c");
	    assertEquals(culprit.getPredicate(), hasValue.asNode());
	    
//	    ont.createTypedLiteral("15", over12Type).getValue();
//	    ont.createTypedLiteral("16", over12Type).getValue();
//	    ont.createTypedLiteral("12", over12Type).getValue();
	}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:30,代碼來源:TestUserDefinedDatatype.java

示例7: test

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Test
public void test() {
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
	
	// Create the Classes : animal, plant, sheep, grass, vegetarian;
	OntClass animal = model.createClass(NS + "Animal");
	OntClass plant = model.createClass(NS + "Plant");
	OntClass sheep = model.createClass(NS + "Sheep");
	OntClass grass = model.createClass(NS + "Grass");
	OntClass vegetarian = model.createClass(NS + "Vegetarian");
	
	// Set sheep as subClass of animal, set grass as subClass of plant;
	animal.addSubClass(sheep);
	plant.addSubClass(grass);
	
	// Create the object property eat and part_of (there domain and range are owl:Thing); 
	ObjectProperty eat = model.createObjectProperty(NS + "eat");
	ObjectProperty partOf = model.createObjectProperty(NS + "partOf");
	
	// Create Restriction : eatAllGrass, set sheep as its subclass;
	AllValuesFromRestriction avr = model.createAllValuesFromRestriction(null, eat, grass);
	avr.addSubClass(sheep);
	
	// Create Restriction : partofSomePlant; partofSomeAnimal;
	SomeValuesFromRestriction plantPart = model.createSomeValuesFromRestriction(null, partOf, plant);
	SomeValuesFromRestriction animalPart = model.createSomeValuesFromRestriction(null, partOf, animal);
	
	// Create the Union Class meat : (animal, partofSomeAnimal);
	RDFNode[] nodes1 = {animal, animalPart};
	RDFList meatList = model.createList(nodes1);
	UnionClass meat = model.createUnionClass(null, meatList);
	
	// Create the Union Class vegetable : (plant, partofSomePlant):
	RDFNode[] nodes2 = {plant, plantPart};
	RDFList vegetableList = model.createList(nodes2);
	UnionClass vegetable = model.createUnionClass(null, vegetableList);

	model.write(System.out, "RDF/XML-ABBREV");
	model.write(System.out, "N3");
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:41,代碼來源:TestCreateUnionClass.java

示例8: dumpModelToLogger

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private void dumpModelToLogger(OntModel model) {
	ByteArrayOutputStream os = new ByteArrayOutputStream(); 
	model.write(os); 
	try {
		String aString = new String(os.toByteArray(),"UTF-8");
		logger.debug(aString);
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:12,代碼來源:JenaReasonerPlugin.java

示例9: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
	String filename = "example5.rdf";
	
	// Create an empty model
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
	
	// Use the FileManager to find the input file
	InputStream in = FileManager.get().open(filename);

	if (in == null)
		throw new IllegalArgumentException("File: "+filename+" not found");

	// Read the RDF/XML file
	model.read(in, null);
	
	// ** TASK 6.1: Create a new class named "University" **
	model.createClass(ns+"University");
	
	// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
	model.getOntClass(ns+"Person").addSubClass(model.createClass(ns+"Researcher"));
	
	// ** TASK 6.3: Create a new property named "worksIn" **
	model.createProperty(ns+"worksIn");
	
	// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
	model.getOntClass(ns+"Researcher").createIndividual(ns+"JaneSmith");
	
	// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
	model.getIndividual(ns+"JaneSmith").addProperty(VCARD.FN, "Jane Smith");
	model.getIndividual(ns+"JaneSmith").addProperty(VCARD.Given, "Jane");
	model.getIndividual(ns+"JaneSmith").addProperty(VCARD.Family, "Smith");
	
	// ** TASK 6.6: Add UPM as the university where John works **
	model.getIndividual(ns+"JohnSmith").addProperty(model.getProperty(ns+"worksIn"), model.getOntClass(ns+"University").createIndividual(ns+"UPM"));
	
	model.write(System.out, "RDF/XML-ABBREV");
}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:39,代碼來源:Task06_Tubilok.java

示例10: testUploadedData

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * Test is new infered data is uploaded into Fuseki server. To do this it is needed.
 *
 *          --> A Fuseki server runing in localhost int port 3030
 *          ---> A city4age dataset created into Fuseki Server
 *
 */
@Test
public void testUploadedData() throws Exception {
    boolean res = false;
    InfModel inf = ModelFactory.createInfModel(this.myReasoner, this.instances);
    final OntModel finalResult = ModelFactory.createOntologyModel();


    finalResult.add(this.instances);
    finalResult.add(inf.getDeductionsModel());
    // Set prefix map
    finalResult.setNsPrefixes(this.instances.getNsPrefixMap());
    finalResult.setNsPrefixes(inf.getDeductionsModel().getNsPrefixMap());

    // Converting final result to string and writ it
    StringWriter out = new StringWriter();
    finalResult.write(out, "RDF/XML");
    String result = out.toString();
    // Launch curl to upload or current knowledge into Fuseki
    ProcessBuilder p = new ProcessBuilder("curl", "-k", "-X", "POST", "--header", "Content-Type: application/rdf+xml",
            "-d", result, "http://localhost:3030/city4age/data");
    try {
        System.out.println("Uploading new Knowledge to Fuseki......................");
        System.out.println("");
        // Execute our command
        final Process shell = p.start();
        // catch output and see if all is ok
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(shell.getInputStream()));
        StringBuilder builder = new StringBuilder();
        String line = null;
        while ( (line = reader.readLine()) != null) {
            builder.append(line);
            builder.append(System.getProperty("line.separator"));
        }
        String output = builder.toString();
        if (output.length() > 0 && output.contains("count")) {
            // We have good response from the server
            res = true;
        }else {
            System.err.println("Some error happened. Is Fuseki activated?");
        }
    }catch (IOException e) {
        e.printStackTrace();
    }

    // Asserting the result
    assertTrue(res);
}
 
開發者ID:aitoralmeida,項目名稱:c4a_data_repository,代碼行數:56,代碼來源:RuleEngineTest.java

示例11: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
	String filename = "example5.rdf";
	
	// Create an empty model
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
	
	// Use the FileManager to find the input file
	InputStream inStr = FileManager.get().open(filename);

	if (inStr == null)
		throw new IllegalArgumentException("File: "+filename+" not found");

	// Read the RDF/XML file
	model.read(inStr, null);
	
	// Create a new class named "Researcher"
	OntClass researcher = model.createClass(ns + "Researcher");
	
	// ** TASK 6.1: Create a new class named "University" **
	OntClass university = model.createClass(ns + "University");
	
	// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
	OntClass person = model.createClass(ns + "Person");
	person.addSubClass(researcher);
	
	// ** TASK 6.3: Create a new property named "worksIn" **
	Property worksIn = model.createProperty(ns+"worksIn");
	
	// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
	Individual janeSmith = researcher.createIndividual(ns + "JaneSmith");		
	
	// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
	janeSmith.addProperty(VCARD.FN, "Jane Smith");
	janeSmith.addProperty(VCARD.Family, "Smith");
	
	
	// ** TASK 6.6: Add UPM as the university where John Smith works **
	Individual upm = university.createIndividual(ns + "UPM");
	Individual johnSmith = model.getIndividual(ns + "JohnSmith");
	johnSmith.addProperty(worksIn, upm);
	
	
	model.write(System.out, "RDF/XML-ABBREV");
}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:46,代碼來源:Task06_IsaacOlguin.java

示例12: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
	String filename = "example5.rdf";
	
	// Create an empty model
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
	
	// Use the FileManager to find the input file
	InputStream in = FileManager.get().open(filename);

	if (in == null)
		throw new IllegalArgumentException("File: "+filename+" not found");

	// Read the RDF/XML file
	model.read(in, null);
	
	// Create a new class named "Researcher"
	OntClass researcher = model.createClass(ns+"Researcher");
	
	// ** TASK 6.1: Create a new class named "University" **
	OntClass university = model.createClass(ns+"University");
	
	// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
	model.getOntClass(ns+"Person").addSubClass(model.createClass(ns+"Researcher"));
	
	// ** TASK 6.3: Create a new property named "worksIn" **
	Property worksIn = model.createProperty(ns+"worksIn");
	
	// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
	Individual janeSmith = researcher.createIndividual(ns+"JaneSmith");
	
	// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
	janeSmith.addProperty(VCARD.FN, "JaneSmith");
	janeSmith.addProperty(VCARD.Given, "Jane");
	janeSmith.addProperty(VCARD.Family, "Smith");
	
	// ** TASK 6.6: Add UPM as the university where John Smith works **
       Individual upm = university.createIndividual(ns + "UPM");
       Individual john = model.getIndividual(ns + "JohnSmith");

       john.addProperty(worksIn, upm);
	
	model.write(System.out, "TURTLE");
}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:45,代碼來源:cesoriano_Task06.java

示例13: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
	String filename = "example5.rdf";
	
	// Create an empty model
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
	
	// Use the FileManager to find the input file
	InputStream in = FileManager.get().open(filename);

	if (in == null)
		throw new IllegalArgumentException("File: "+filename+" not found");

	// Read the RDF/XML file
	model.read(in, null);
	
	// Create a new class named "Researcher"
	OntClass researcher = model.createClass(ns+"Researcher");
	
	// ** TASK 6.1: Create a new class named "University" **
	OntClass university = model.createClass(ns+"University");
	
	// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
	OntClass person = model.createClass(ns + "Person");
	person.addSubClass(researcher);
	
	// ** TASK 6.3: Create a new property named "worksIn" **
	Property worksIn=model.createProperty(ns+"worksIn");
	
	// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
	Individual janeSmith =researcher.createIndividual(ns+"JaneSmith");
	
	// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
	janeSmith.addLiteral(VCARD.FN, "Jane Smith");
	janeSmith.addLiteral(VCARD.Given, "Jane");
	janeSmith.addLiteral(VCARD.Family, "Smith");
	
	
	// ** TASK 6.6: Add UPM as the university where John Smith works **
	Individual johnSmith = model.getIndividual(ns+"JohnSmith");
	Individual uPM= university.createIndividual(ns+"UPM");
	johnSmith.addProperty(worksIn, uPM);
	
	
	model.write(System.out, "RDF/XML-ABBREV");
}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:47,代碼來源:Task06_kainruben.java

示例14: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
	String filename = "example5.rdf";
	
	// Create an empty model
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
	
	// Use the FileManager to find the input file
	InputStream in = FileManager.get().open(filename);

	if (in == null)
		throw new IllegalArgumentException("File: "+filename+" not found");

	// Read the RDF/XML file
	model.read(in, null);
	
	// Create a new class named "Researcher"
	OntClass researcher = model.createClass(ns+"Researcher");
	
	// ** TASK 6.1: Create a new class named "University" **
	OntClass university = model.createClass(ns+"University");
	
	// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
	model.getOntClass(ns+"Person").addSubClass(university);
	
	// ** TASK 6.3: Create a new property named "worksIn" **
	Property worksIn = model.createProperty(ns+"WorksIn");
	
	// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
	Individual janeSmith = researcher.createIndividual(ns+"JaneSmith");
	
	// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
	janeSmith.addProperty(VCARD.FN, "JaneSmith");
	janeSmith.addProperty(VCARD.Given, "Jane");
	janeSmith.addProperty(VCARD.Family, "Smith");
	
	// ** TASK 6.6: Add UPM as the university where John Smith works **
	Individual johnSmith = model.getIndividual(ns+"JaneSmith");
	johnSmith.addProperty(worksIn, university.createIndividual(ns+"UPM"));
	
	model.write(System.out, "RDF/XML-ABBREV");
	System.out.println("\n---------------------------------------------\n");
	model.write(System.out, "TURTLE");
}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:45,代碼來源:Task06_Nestor_Lopez.java

示例15: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
	String filename = "example5.rdf";
	
	// Create an empty model
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
	
	// Use the FileManager to find the input file
	InputStream in = FileManager.get().open(filename);

	if (in == null)
		throw new IllegalArgumentException("File: "+filename+" not found");

	// Read the RDF/XML file
	model.read(in, null);
	
	// Create a new class named "Researcher"
	OntClass researcher = model.createClass(ns+"Researcher");
	
	// ** TASK 6.1: Create a new class named "University" **
	OntClass university = model.createClass(ns+"University");
	
	// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
	model.getOntClass(ns+"Person").addSubClass(researcher);
	
	// ** TASK 6.3: Create a new property named "worksIn" **
	Property worksIn = model.createProperty(ns + "WorkIn");
	
	// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
	Individual janeSmith = researcher.createIndividual(ns + "Jane Smith");
	
	// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
	janeSmith.addProperty(VCARD.FN, "Jane Smith");
	janeSmith.addProperty(VCARD.Given, "Jane");
	janeSmith.addProperty(VCARD.Family, "Smith");

	
	// ** TASK 6.6: Add UPM as the university where John Smith works **
	Individual upm = university.createIndividual(ns + "UPM");
	model.getIndividual(ns + "John Smith").addProperty(worksIn, upm);
	
	model.write(System.out, "RDF/XML-ABBREV");
}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:44,代碼來源:Task06_Ivan_Diez.java


注:本文中的com.hp.hpl.jena.ontology.OntModel.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。