Package com.hp.hpl.jena.ontology.tidy.test

Source Code of com.hp.hpl.jena.ontology.tidy.test.TestOntModel

/*****************************************************************************
* Source code information
* -----------------------
* Original author    Ian Dickinson, HP Labs Bristol
* Author email       Ian.Dickinson@hp.com
* Package            Jena 2
* Web                http://sourceforge.net/projects/jena/
* Created            21-Jun-2003
* Filename           $RCSfile: TestOntModel.java,v $
* Revision           $Revision: 1.2 $
* Release status     $State: Exp $
*
* Last modified on   $Date: 2005/04/12 11:03:24 $
*               by   $Author: jeremy_carroll $
*
* (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
* (see footer for full conditions)
*****************************************************************************/

// Package
///////////////
package com.hp.hpl.jena.ontology.tidy.test;


// Imports
///////////////
import java.io.*;
import java.util.*;
import java.util.List;

import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.ontology.tidy.SyntaxProblem;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.rdf.model.test.*;
import com.hp.hpl.jena.vocabulary.OWL;



/**
* <p>
* Unit tests on OntModel capabilities.  Many of OntModel's methods are tested by the other
* abstractions' unit tests.
* </p>
*
* @author Ian Dickinson, HP Labs
*         (<a  href="mailto:Ian.Dickinson@hp.com" >email</a>)
* @version CVS $Id: TestOntModel.java,v 1.2 2005/04/12 11:03:24 jeremy_carroll Exp $
*/
public class TestOntModel
    extends ModelTestBase
{
    // Constants
    //////////////////////////////////

    // Static variables
    //////////////////////////////////

    public static final String BASE = "http://www.hp.com/test";
    public static final String NS = BASE + "#";
   
   
    // Instance variables
    //////////////////////////////////

    // Constructors
    //////////////////////////////////

    public TestOntModel( String name ) {
        super( name );
    }
   
    // External signature methods
    //////////////////////////////////

    public void setUp() {
        // ensure the ont doc manager is in a consistent state
        OntDocumentManager.getInstance().reset( true );
    }
   

    /** Test case from Robert N Gonzalez [mailto:rngonzal@us.ibm.com] via jena-dev: exception while checking an ontology that imports a URN */
    public void test_rng_01() {
        String SOURCE=
            "<?xml version='1.0'?>" +
            "<!DOCTYPE owl [" +
            "      <!ENTITY rdf  'http://www.w3.org/1999/02/22-rdf-syntax-ns#' >" +
            "      <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#' >" +
            "      <!ENTITY xsd  'http://www.w3.org/2001/XMLSchema#' >" +
            "      <!ENTITY owl  'http://www.w3.org/2002/07/owl#' >" +
            "      <!ENTITY dc   'http://purl.org/dc/elements/1.1/' >" +
            "      <!ENTITY base  'http://jena.hpl.hp.com/test' >" +
            "    ]>" +
            "<rdf:RDF xmlns:owl ='&owl;' xmlns:rdf='&rdf;' xmlns:rdfs='&rdfs;' xmlns:dc='&dc;' xmlns='&base;#' xml:base='&base;'>" +
            "         <owl:Ontology rdf:about='urn:someURN:'> " +
            "                 <owl:imports>" +
            "                   <owl:Ontology rdf:about='urn:ALegalURN:' />" +
            "                 </owl:imports>" +
            "         </owl:Ontology>" +
            "</rdf:RDF>";
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
        m.getDocumentManager()
         .addAltEntry( "urn:ALegalURN:", "file:testing/ontology/bugs/test_hk_07B.owl" );
        m.getDocumentManager().setProcessImports( false );
        m.read( new StringReader( SOURCE ), null );
        List problems = new ArrayList();
        Resource level = m.getOWLLanguageLevel( problems );
        //System.out.println( "level = " + level );
        for (Iterator i = problems.iterator(); i.hasNext(); ) {
            SyntaxProblem sp = (SyntaxProblem) i.next();
            //System.out.println( "problem = " + sp.longDescription() );
        }
    }


   
    public void testChecker1() {
        String NS = "http://example.org/test#";
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM, null );
        m.createClass( NS + "A" );
       
        // note, just checking the process not the coverage of the syntax checker
        List probs = new ArrayList();
        assertEquals( "Should be owl lite", OWL.LITE_LANG, m.getOWLLanguageLevel( null ));
        assertEquals( "Should be owl lite", OWL.LITE_LANG, m.getOWLLanguageLevel( probs ));
        assertTrue( "should be no problems", probs.isEmpty() );
    }
   
    public void testChecker2() {
        String NS = "http://example.org/test#";
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null );
        m.createClass( NS + "A" );
       
        // note, just checking the process not the coverage of the syntax checker
        List probs = new ArrayList();
        assertEquals( "Should be owl lite", OWL.LITE_LANG, m.getOWLLanguageLevel( null ));
        assertEquals( "Should be owl lite", OWL.LITE_LANG, m.getOWLLanguageLevel( probs ));
        assertTrue( "should be no problems", probs.isEmpty() );
    }
   
    public void testChecker3() {
        String NS = "http://example.org/test#";
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM, null );
       
        // contains non owl-lite class exprs
        m.read( "file:testing/ontology/test-boolean.rdf");
       
        // note, just checking the process not the coverage of the syntax checker
        List probs = new ArrayList();
        //assertEquals( "Should be owl DL", OWL.DL_LANG, m.getOWLLanguageLevel( null ));
        assertEquals( "Should be owl DL", OWL.DL_LANG, m.getOWLLanguageLevel( probs ));
        assertTrue( "should be some problems", !probs.isEmpty() );
    }
   
    public void testChecker4() {
        String NS = "http://example.org/test#";
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null );
       
        // contains non owl-lite class exprs
        m.read( "file:testing/ontology/test-boolean.rdf");
       
        // note, just checking the process not the coverage of the syntax checker
        List probs = new ArrayList();
        assertEquals( "Should be owl DL", OWL.DL_LANG, m.getOWLLanguageLevel( null ));
        assertEquals( "Should be owl DL", OWL.DL_LANG, m.getOWLLanguageLevel( probs ));
        assertTrue( "should be no problems", probs.isEmpty() );
    }
   
    public void testChecker5() {
        String NS = "http://example.org/test#";
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM, null );
       
        OntClass A = m.createClass( NS + "A" );
        ObjectProperty p = m.createObjectProperty( NS + "p" );
        Resource B = m.createResource( NS + "B" );
        m.createAllValuesFromRestriction( null, p, B );
       
        // note, just checking the process not the coverage of the syntax checker
        List probs = new ArrayList();
        assertEquals( "Should be owl Full", OWL.FULL_LANG, m.getOWLLanguageLevel( null ));
        assertEquals( "Should be owl Full", OWL.FULL_LANG, m.getOWLLanguageLevel( probs ));
        assertTrue( "should be problems", !probs.isEmpty() );
    }
   
    public void testChecker6() {
        String NS = "http://example.org/test#";
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null );
       
        OntClass A = m.createClass( NS + "A" );
        ObjectProperty p = m.createObjectProperty( NS + "p" );
        Resource B = m.createResource( NS + "B" );
        m.createAllValuesFromRestriction( null, p, B );
       
        // note, just checking the process not the coverage of the syntax checker
        List probs = new ArrayList();
        assertEquals( "Should be owl Full", OWL.FULL_LANG, m.getOWLLanguageLevel( null ));
        assertEquals( "Should be owl Full", OWL.FULL_LANG, m.getOWLLanguageLevel( probs ));
        assertTrue( "should be problems", !probs.isEmpty() );
    }
   
    public void testChecker7() {
        String NS = "http://example.org/test#";
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
       
        OntClass A = m.createClass( NS + "A" );
        ObjectProperty p = m.createObjectProperty( NS + "p" );
        Resource B = m.createResource( NS + "B" );
        m.createAllValuesFromRestriction( null, p, B );
       
        // note, just checking the process not the coverage of the syntax checker
        List probs = new ArrayList();
        assertEquals( "Should be owl Full", OWL.FULL_LANG, m.getOWLLanguageLevel( null ));
        assertEquals( "Should be owl Full", OWL.FULL_LANG, m.getOWLLanguageLevel( probs ));
        assertTrue( "should be problems", !probs.isEmpty() );
    }
   
    public void testChecker8() {
        boolean ex = false;
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.DAML_MEM, null );
       
        try {
            m.getOWLLanguageLevel( null );
        }
        catch (OntologyException e) {
            ex = true;
        }
       
        assertTrue( "Should have raised exception to get owl lang level on non-owl model", ex );
    }
}


/*
    (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. The name of the author may not be used to endorse or promote products
       derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

 
TOP

Related Classes of com.hp.hpl.jena.ontology.tidy.test.TestOntModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.