/*
(c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
All rights reserved.
$Id$
*/
package run;
import java.io.PrintStream;
import java.util.List;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.shared.PrefixMapping;
import com.hp.jena.ymris.deploy.reasoner.DirectReasoner;
import com.hp.jena.ymris.yast.*;
import com.hp.jena3.rules.acceptance.*;
import run.acceptance.support.State;
public class accept
{
public static void main( String [] args )
{
throw new UnsupportedOperationException( "TBD" );
// Arguments a = new Arguments( "tests", args );
// String fileName = a.valueFor( "tests", null );
// runAcceptance( ReaderUtils.readFile( fileName ), System.out );
}
public static void runAcceptance( String content, PrintStream out )
{
State state = new State();
for (ScriptElement e: new ScriptParser().parse( content ))
{
String c = e.getCommand(), b = e.getBody();
if (c.equals( "ruleset" ))
state.setRulesFromString( b );
else if (c.equals( "rdf" ))
state.setModelfromString( b );
else if (c.equals( "expect" ))
state.expectModel( b );
else if (c.equals( "title" ))
state.addTitle( collapse( e.getArguments() ) );
else if (c.equals( "comment" ))
state.addComment( b );
else throw new RuntimeException( "don't understand command: " + c );
}
state.displayResults( out );
}
private static String collapse( List<String> strings )
{
StringBuffer result = new StringBuffer();
for (String s: strings) result.append( " " ).append( s );
return result.toString();
}
public static Model applyRules( YAST yast, Model m )
{
List<RuleSet> ruleSets = yast.ruleSets();
if (ruleSets.isEmpty())
{
Model result = ModelFactory.createDefaultModel().add( m );
result.setNsPrefixes( m.getNsPrefixMap() );
result.withDefaultMappings( PrefixMapping.Extended );
return result;
}
else
{
Reasoner r = new DirectReasoner( ruleSets.get( 0 ) );
InfGraph ig = r.bind( m.getGraph() );
Model result = ModelFactory.createModelForGraph( ig );
result.setNsPrefixes( m.getNsPrefixMap() );
result.withDefaultMappings( PrefixMapping.Extended );
return result;
}
}
}
/*
(c) Copyright 2009 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.
*/