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

Source Code of com.hp.hpl.jena.ontology.tidy.JenaChecker

/*
* (c) Copyright 2005 Hewlett-Packard Development Company, LP
* [See end of file]
*/

package com.hp.hpl.jena.ontology.tidy;

import java.util.Iterator;
import java.util.List;

import com.hp.hpl.jena.ontology.OWLSyntaxChecker;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntologyException;
import com.hp.hpl.jena.ontology.Profile;
import com.hp.hpl.jena.ontology.impl.OWLLiteProfile;
import com.hp.hpl.jena.ontology.impl.OWLProfile;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.OWL;

/**
*
* <p>This class is a wrapper implementing the
* {@link OWLSyntaxChecker} interface, that provides
* a first version of linking the separate owlsyntax.jar download
* in with Jena (version 2.2 and beyond).
* </p>
* <p>It is intended as part of an SPI for the jena development team,
* and not an API for use by developers using jena;
* in particular, it may change, without deprecation etc.</p>
*
* @author Jeremy J. Carroll
*
*/
public class JenaChecker implements OWLSyntaxChecker {

    /* (non-Javadoc)
     * @see com.hp.hpl.jena.ontology.OWLSyntaxChecker#getOWLLanguageLevel(com.hp.hpl.jena.ontology.OntModel, java.util.List)
     */
    public Resource getOWLLanguageLevel(OntModel owlModel, List problems)
            throws OntologyException {
// Code from OntModelImpl.getOWLLanguageLevel version 2.2 beta
        Profile oProf = owlModel.getProfile();
        if (!(oProf instanceof OWLProfile)) {
            throw new OntologyException( "Cannnot perform OWL language level test on non OWL model" );
        }
       
        // this process is made complicated by the design of the syntax checker, which uses
        // two different grammars for Lite and DL checking.  in some circumstances, we have
        // to run both kinds of check
       
        // using expectLite = false gives the most complete result (lite, dl or full)
        Checker checker = new Checker( false );
        checker.add( owlModel );
       
        // do the check, and collect any problem reports
        String lang = checker.getSubLanguage();
       
        // if we are expecting lite, we want to re-run to get better explanations
        if ((oProf instanceof OWLLiteProfile ) && !lang.equals( "Lite" ) && (problems != null)) {
            checker = new Checker( true );
            checker.add( owlModel );
            checker.getSubLanguage();
        }
       
        if (problems != null) {
            for (Iterator i = checker.getProblems(); i.hasNext(); ) {
                problems.add( i.next() );
            }
        }
       
        // determine the return value
        if (lang.equals( "Lite" )) {
            return OWL.LITE_LANG;
        }
        else if (lang.equals( "DL" )) {
            return OWL.DL_LANG;
        }
        else {
            return OWL.FULL_LANG;
        }
    }

}


/*
*  (c) Copyright 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.JenaChecker

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.