001 /** 002 * OntoBride library 003 * Departamento de Ingeniería del Software e Inteligencia Artificial 004 * Universidad Complutense de Madrid 005 * 006 * Licensed under the terms of the GNU Library or Lesser General Public License (LGPL) 007 * 008 * @author Juan A. Recio García 009 * 010 * This software is a subproject of the jCOLIBRI framework 011 * http://sourceforge.net/projects/jcolibri-cbr/ 012 * http://gaia.fdi.ucm.es/projects/jcolibri/ 013 * 014 * File: Test4.java 015 * 26/02/2007 016 */ 017 package es.ucm.fdi.gaia.ontobridge.test; 018 019 import java.util.ArrayList; 020 import java.util.Iterator; 021 022 import es.ucm.fdi.gaia.ontobridge.OntoBridge; 023 import es.ucm.fdi.gaia.ontobridge.OntologyDocument; 024 import es.ucm.fdi.gaia.ontobridge.test.gui.PnlConceptsAndInstancesTree; 025 026 /** 027 * File used for testing the library using the GAIA photos ontology. 028 * Shows a graphical representation that includes instances. 029 * It also shows how to create new classes and instances, and how to write the modifications into a file. 030 * 031 * @author Juan A. Recio Garcia 032 */ 033 public class Test4 { 034 035 public static void main(String args[]) 036 { 037 OntoBridge ob = new OntoBridge(); 038 ob.initWithPelletReasoner(); 039 040 OntologyDocument mainOnto = new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/fotos.owl","file:test/fotos.owl"); 041 ArrayList<OntologyDocument> subOntologies = new ArrayList<OntologyDocument>(); 042 043 ob.loadOntology(mainOnto, subOntologies, false); 044 ob.createClass("Vacaciones"); 045 ob.setSubClass("Vacaciones", "Foto"); 046 ob.createInstance("Vacaciones", "fotov1"); 047 ob.createOntProperty("fotov1", "aparecePersona", "Ana"); 048 ob.createDataTypeProperty("fotov1", "urlfoto", "file://c:/fotosvacaciones/fotov1.jpg"); 049 ob.createDataTypeProperty("fotov1", "fecha", "2007-02-25", "http://www.w3.org/2001/XMLSchema#date"); 050 051 Iterator<String> fotos = ob.listInstances("Foto"); 052 while(fotos.hasNext()) 053 { 054 String instance = fotos.next(); 055 System.out.println(instance); 056 ArrayList<String> properties = new ArrayList<String>(); 057 ArrayList<String> values = new ArrayList<String>(); 058 ob.listInstancePropertiesValues(instance, properties, values); 059 for(int i=0; i<properties.size(); i++) 060 System.out.println(properties.get(i)+" --> "+ values.get(i)); 061 } 062 063 064 javax.swing.JFrame window = new javax.swing.JFrame(mainOnto.getURL()); 065 PnlConceptsAndInstancesTree tree = new PnlConceptsAndInstancesTree(ob); 066 window.getContentPane().add(tree); 067 window.pack(); 068 window.setSize(300, 600); 069 window.setVisible(true); 070 071 //ob.save("newonto.owl"); 072 } 073 }