/** * File: Test_1.java */ import edu.uga.cs.lsdis.semdisds.IBlankNode; import edu.uga.cs.lsdis.semdisds.IExtendedIterator; import edu.uga.cs.lsdis.semdisds.IInstanceNode; import edu.uga.cs.lsdis.semdisds.ILiteral; import edu.uga.cs.lsdis.semdisds.ILiteralRange; import edu.uga.cs.lsdis.semdisds.ILiteralStatement; import edu.uga.cs.lsdis.semdisds.IOntologyModel; import edu.uga.cs.lsdis.semdisds.IResource; import edu.uga.cs.lsdis.semdisds.IResourceStatement; import edu.uga.cs.lsdis.semdisds.ISchemaClass; import edu.uga.cs.lsdis.semdisds.ISchemaDatatypeProperty; import edu.uga.cs.lsdis.semdisds.ISchemaObjectProperty; import edu.uga.cs.lsdis.semdisds.ISchemaProperty; import edu.uga.cs.lsdis.semdisds.ITypeOfStatement; import edu.uga.cs.lsdis.semdis.model.UgaOntologyModel; import java.util.Map; import java.util.Set; /** * Test of Implementation of SemDis API * * * @version 0.1 * @author Boanerges Aleman-Meza * @created 2006-03-17 * * */ public class Test_1 { /************************************************************ * Command-line testing purposes only * @param args self-explanatory */ public static void main( String[] args ) { boolean flag = false; IOntologyModel ontologyModel = new UgaOntologyModel(); ILiteral literal = null; // load stuff ontologyModel.loadOntology( "file:///c://temp//2005-10-04__phase2_statements.rdf" ); ontologyModel.loadOntology( "file:///c://temp//2005-10-04__phase2_schema.rdf" ); System.err.println( "------------------------------------------------------------------------------" ); System.err.println( "Classes:" ); for( ISchemaClass schemaClass : ontologyModel.getSchemaClasses() ) { System.err.println( " " + schemaClass + " (" + schemaClass.getInstancesCount() + " instances)" ); // output the literals for( ILiteralStatement literalStatement : schemaClass.getLiterals() ) { literal = literalStatement.getObject(); System.err.println( " '" + literal + "' (" + literalStatement.getPredicate().getShortName() + ")" ); }; // for // output the parents flag = false; for( ISchemaClass ancestorSchemaClass : schemaClass.getParents() ) { System.err.print( flag == true ? "" : " parents: " ); flag = true; System.err.print( " " + ancestorSchemaClass.getShortName() ); }; // for System.err.print( flag == true ? "\n" : "" ); // output the ancestors flag = false; for( ISchemaClass ancestorSchemaClass : schemaClass.getAncestors() ) { System.err.print( flag == true ? "" : " ancestors:" ); flag = true; System.err.print( " " + ancestorSchemaClass.getShortName() ); }; // for System.err.print( flag == true ? "\n" : "" ); // output the children flag = false; for( ISchemaClass childSchemaClass : schemaClass.getChildren() ) { System.err.print( flag == true ? "" : " children: " ); flag = true; System.err.print( " " + childSchemaClass.getShortName() ); }; // for System.err.print( flag == true ? "\n" : "" ); // output incoming edges for( IResourceStatement resourceStatement : schemaClass.getIncomingEdges() ) { System.err.println( " <--" + resourceStatement.getPredicate().getShortName() + "<-- " + resourceStatement.getSubject().getShortName() ); }; // for // output outgoing edges for( IResourceStatement resourceStatement : schemaClass.getOutgoingEdges() ) { System.err.println( " -->" + resourceStatement.getPredicate().getShortName() + "--> " + resourceStatement.getObject().getShortName() ); }; // for }; // for System.err.println( "------------------------------------------------------------------------------" ); System.err.println( "Instances for each class:" ); for( ISchemaClass schemaClass : ontologyModel.getSchemaClasses() ) { System.err.println( " " + schemaClass + " (" + schemaClass.getInstancesCount() + " instances)" ); // output direct instances flag = false; for( IInstanceNode instanceNode : schemaClass.getInstances() ) { System.err.print( flag == true ? "" : " direct: " ); flag = true; System.err.print( " " + instanceNode.getShortName() ); }; // for System.err.print( flag == true ? "\n" : "" ); // output subtype instances flag = false; for( IInstanceNode instanceNode : schemaClass.getSubTypeInstances() ) { System.err.print( flag == true ? "" : " subtype:" ); flag = true; System.err.print( " " + instanceNode.getShortName() ); }; // for System.err.print( flag == true ? "\n" : "" ); }; // for System.err.println( "------------------------------------------------------------------------------" ); System.err.println( "Properties:" ); for( ISchemaProperty schemaProperty : ontologyModel.getSchemaProperties() ) { System.err.println( " " + schemaProperty.getURI() ); // output the parents flag = false; for( ISchemaProperty ancestorSchemaProperty : schemaProperty.getParents() ) { System.err.print( flag == true ? "" : " parents: " ); flag = true; System.err.print( " " + ancestorSchemaProperty.getShortName() ); }; // for System.err.print( flag == true ? "\n" : "" ); }; // for System.err.println( "------------------------------------------------------------------------------" ); outputClassHierarchy( System.err, ontologyModel ); }; // main /** * Outputs the hierarchy of classes * @param output the print-stream to output to * @param ontologyModel the ontology model */ public static void outputClassHierarchy( java.io.PrintStream output, IOntologyModel ontologyModel ) { output.println( "Classes Hierarchy:" ); IExtendedIterator extendedIterator = null; for( ISchemaClass schemaClass : ontologyModel.getSchemaClasses() ) { extendedIterator = schemaClass.getParents(); if( extendedIterator.size() > 0 ) { outputClassHierarchyAux( output, schemaClass, " " ); }; // if }; // for output.flush(); }; // outputClassHierarchy /** * Outputs the hierarchy of classes (auxiliary method) * @param output the print-stream to output to * @param ontologyModel the ontology model */ public static void outputClassHierarchyAux( java.io.PrintStream output, ISchemaClass schemaClass, String spaces ) { if( spaces == null ) { spaces = ""; }; // if output.println( spaces + schemaClass ); for( ISchemaClass childSchemaClass : schemaClass.getChildren() ) { outputClassHierarchyAux( output, childSchemaClass, spaces + " " ); }; // for }; // outputClassHierarchyAux }; // class Test_1