Skip to content

Commit

Permalink
add to the number of places that validFunctionSources is passed to
Browse files Browse the repository at this point in the history
  • Loading branch information
ansell committed Nov 9, 2011
1 parent 6041653 commit 837720b
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.topbraid.spin.model.print.Printable;

Expand Down Expand Up @@ -44,5 +45,8 @@ public interface FunctionCall extends Printable, ModuleCall {
* Model, for example if loaded into the library from a .spin. file.
* @return the function in its original Model
*/
Resource getFunction();
Resource getFunction();


Resource getFunction(Set<Object> validFunctionSources);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*******************************************************************************/
package org.topbraid.spin.model;

import java.util.Set;

import com.hp.hpl.jena.rdf.model.Resource;


Expand All @@ -15,4 +17,7 @@
public interface ModuleCall extends Resource {

Module getModule();

Module getModule(Set<Object> validFunctionSources);

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ public Map<Property, RDFNode> getArgumentsMap() {
return values;
}


@Override
public Resource getFunction() {
return getFunction(null);
}

@Override
public Resource getFunction(Set<Object> validFunctionSources) {

// Need to iterate over rdf:types - some may have been inferred
Expand Down Expand Up @@ -146,7 +147,12 @@ else if(!getModel().contains(null, RDFS.subClassOf, candidate)) {

@Override
public Module getModule() {
Resource function = getFunction();
return getModule(Collections.emptySet());
}

@Override
public Module getModule(Set<Object> validFunctionSources) {
Resource function = getFunction(validFunctionSources);
if(function != null) {
return function.as(Function.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
*******************************************************************************/
package org.topbraid.spin.model.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.topbraid.spin.model.Argument;
import org.topbraid.spin.model.Module;
Expand Down Expand Up @@ -89,7 +91,12 @@ public Map<String, RDFNode> getArgumentsMapByVarNames() {

@Override
public Module getModule() {
return getTemplate();
return getModule(Collections.emptySet());
}

@Override
public Module getModule(Set<Object> validFunctionSources) {
return getTemplate();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private class MyExpressionVisitor extends AbstractExpressionVisitor {

@Override
public void visit(FunctionCall functionCall, Set<Object> validFunctionSources) {
Resource function = functionCall.getFunction();
Resource function = functionCall.getFunction(validFunctionSources);
if(function != null && function.isURIResource() && !reachedFunctionCalls.contains(functionCall)) {
reachedFunctionCalls.add(functionCall);
Resource f = SPINModuleRegistry.get().getFunction(function.getURI(), null, validFunctionSources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public void setUp() throws Exception
this.testFiles1.add("/owlrl.owl");
this.testFiles1.add("/owlrl-all.owl");

this.testFiles2 = new ArrayList<String>(3);
this.testFiles2 = new ArrayList<String>(4);
this.testFiles2.add("/sp.owl");
this.testFiles2.add("/spl.owl");
this.testFiles2.add("/spin.owl");
this.testFiles1.add("/owlrl.owl");
this.testFiles2.add("/owlrl.owl");

this.testFiles3 = new ArrayList<String>(3);
this.testFiles3 = new ArrayList<String>(1);
this.testFiles3.add("/spinowl.owl");

}
Expand Down Expand Up @@ -267,7 +267,7 @@ public void testGetFunctionsBySourceDummyObject()
// test load from a different source
this.testRegistry.registerAll(SpinTestUtils.loadModelFromTestFiles(this.testFiles2), this.testFiles2);

Assert.assertEquals(60, this.testRegistry.getFunctions().size());
Assert.assertEquals(62, this.testRegistry.getFunctions().size());

functionsBySource = this.testRegistry.getFunctionsBySource(this.testFiles2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,124 @@
*/
package org.topbraid.spin.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.topbraid.spin.util.CommandWrapper;
import org.topbraid.spin.util.SPINQueryFinder;
import org.topbraid.spin.vocabulary.SPIN;

import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.compose.MultiUnion;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.shared.ReificationStyle;
import com.hp.hpl.jena.vocabulary.OWL2;
import com.hp.hpl.jena.vocabulary.RDF;

/**
* @author Peter Ansell [email protected]
*
*/
public class SPINQueryFinderUnitTest
{
static final Logger log = LoggerFactory.getLogger(SPINQueryFinderUnitTest.class);

private SPINModuleRegistry testRegistry = SPINModuleRegistry.get();


private ArrayList<String> testFiles1;


private Map<CommandWrapper, Map<String,RDFNode>> testInitialTemplateBindings;


private Set<Object> testValidFunctionSources;

private Set<Object> testInvalidFunctionSources;

private Model testQueryModel;


private Model testUnionModel;


private Object testObject;

/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception
{
this.testObject = new Object();

this.testRegistry.reset();
this.testRegistry.init();

this.testFiles1 = new ArrayList<String>(5);
this.testFiles1.add("/sp.owl");
this.testFiles1.add("/spl.owl");
this.testFiles1.add("/spin.owl");
this.testFiles1.add("/owlrl.owl");
this.testFiles1.add("/owlrl-all.owl");

OntModel testOntologyModel = SpinTestUtils.loadModelFromTestFiles(testFiles1);

Assert.assertEquals(7094, testOntologyModel.size());

this.testRegistry.registerAll(testOntologyModel, this.testObject);

this.testRegistry.init();

this.testValidFunctionSources = new HashSet<Object>();
this.testValidFunctionSources.add(this.testObject);

testInvalidFunctionSources = new HashSet<Object>();
testInvalidFunctionSources.add(new Object());

this.testInitialTemplateBindings = new HashMap<CommandWrapper, Map<String,RDFNode>>();

List<com.hp.hpl.jena.rdf.model.Statement> jenaStatements = new ArrayList<com.hp.hpl.jena.rdf.model.Statement>(3);

com.hp.hpl.jena.rdf.model.Statement testJenaStatement1 = ResourceFactory.createStatement(ResourceFactory.createResource("http://my.example.org/test/uri/1"), ResourceFactory.createProperty("http://other.example.org/test/property/a1"), ResourceFactory.createTypedLiteral(42));
com.hp.hpl.jena.rdf.model.Statement testJenaStatement2 = ResourceFactory.createStatement(ResourceFactory.createResource("http://my.example.org/test/uri/1"), RDF.type, ResourceFactory.createResource("http://my.example.org/test/uri/testType"));
com.hp.hpl.jena.rdf.model.Statement testJenaStatement3 = ResourceFactory.createStatement(ResourceFactory.createResource("http://my.example.org/test/uri/testType"), OWL2.equivalentClass, ResourceFactory.createResource("http://vocab.org/test/equivalentToRuleType1"));

jenaStatements.add(testJenaStatement1);
jenaStatements.add(testJenaStatement2);
jenaStatements.add(testJenaStatement3);

this.testQueryModel = ModelFactory.createDefaultModel(ReificationStyle.Minimal);

testQueryModel.add(jenaStatements);

Graph[] graphs = new Graph[2];

graphs[0] = testQueryModel.getGraph();
graphs[1] = testOntologyModel.getGraph();

MultiUnion multiUnion = new MultiUnion(graphs);

this.testUnionModel = ModelFactory.createModelForGraph(multiUnion);


}

/**
Expand All @@ -31,14 +129,26 @@ public void setUp() throws Exception
@After
public void tearDown() throws Exception
{
this.testFiles1 = null;

this.testInitialTemplateBindings = null;

this.testValidFunctionSources = null;

this.testUnionModel = null;
this.testQueryModel = null;

this.testRegistry.reset();
this.testRegistry.init();

}

/**
* Test method for {@link org.topbraid.spin.util.SPINQueryFinder#add(java.util.Map, com.hp.hpl.jena.rdf.model.Statement, com.hp.hpl.jena.rdf.model.Model, boolean, java.util.Map, boolean)}.
*/
@Ignore
@Test
public void testAddMapOfResourceListOfCommandWrapperStatementModelBooleanMapOfCommandWrapperMapOfStringRDFNodeBoolean()
public void testAdd()
{
Assert.fail("Not yet implemented"); // TODO
}
Expand All @@ -48,7 +158,7 @@ public void testAddMapOfResourceListOfCommandWrapperStatementModelBooleanMapOfCo
*/
@Ignore
@Test
public void testAddMapOfResourceListOfCommandWrapperStatementModelBooleanMapOfCommandWrapperMapOfStringRDFNodeBooleanSetOfObject()
public void testAddWithValidFunctionSources()
{
Assert.fail("Not yet implemented"); // TODO
}
Expand All @@ -58,19 +168,54 @@ public void testAddMapOfResourceListOfCommandWrapperStatementModelBooleanMapOfCo
*/
@Ignore
@Test
public void testGetClass2QueryMapModelModelPropertyBooleanMapOfCommandWrapperMapOfStringRDFNodeBoolean()
public void testGetClass2QueryMap()
{
Assert.fail("Not yet implemented"); // TODO
}

/**
* Test method for {@link org.topbraid.spin.util.SPINQueryFinder#getClass2QueryMap(com.hp.hpl.jena.rdf.model.Model, com.hp.hpl.jena.rdf.model.Model, com.hp.hpl.jena.rdf.model.Property, boolean, java.util.Map, boolean, java.util.Set)}.
*/
@Ignore
@Test
public void testGetClass2QueryMapModelModelPropertyBooleanMapOfCommandWrapperMapOfStringRDFNodeBooleanSetOfObject()
public void testGetClass2QueryMapWithFunctionSources()
{
Assert.fail("Not yet implemented"); // TODO
Map<Resource,List<CommandWrapper>> cls2Query = SPINQueryFinder.getClass2QueryMap(this.testUnionModel, this.testQueryModel, SPIN.rule, true, testInitialTemplateBindings, false, this.testValidFunctionSources);

Assert.assertEquals(1, cls2Query.size());

for(Resource nextResource : cls2Query.keySet())
{
Assert.assertEquals("http://www.w3.org/2002/07/owl#Thing", nextResource.toString());

Assert.assertEquals(51, cls2Query.get(nextResource).size());

for(CommandWrapper nextCommandWrapper : cls2Query.get(nextResource))
{
log.info(nextCommandWrapper.getSPINCommand().toString());
}

}

Map<Resource,List<CommandWrapper>> emptyCls2Query = SPINQueryFinder.getClass2QueryMap(this.testUnionModel, this.testQueryModel, SPIN.rule, true, testInitialTemplateBindings, false, this.testInvalidFunctionSources);

Assert.assertEquals(1, emptyCls2Query.size());

for(Resource nextResource : cls2Query.keySet())
{
Assert.assertEquals("http://www.w3.org/2002/07/owl#Thing", nextResource.toString());

Assert.assertEquals(51, cls2Query.get(nextResource).size());

for(CommandWrapper nextCommandWrapper : cls2Query.get(nextResource))
{
log.info(nextCommandWrapper.getSPINCommand().toString());
}

}

Map<Resource,List<CommandWrapper>> cls2Constructor = SPINQueryFinder.getClass2QueryMap(this.testQueryModel, this.testQueryModel, SPIN.constructor, true, testInitialTemplateBindings, false, this.testValidFunctionSources);

Assert.assertEquals(0, cls2Constructor.size());
}

}

0 comments on commit 837720b

Please sign in to comment.