Hi Holger,

Hmm when I narrowed down the problem I didn't use an ont-policy anymore.
Perhaps it's something system dependent, but I don't really see what the 
problem might be. I'm using spinapi-1.4.0 and jena 2.11.0 (although 2.11.2 
and 2.12.0 give the exact same problem).
I've attached both the example code and the modified kennedysSPIN.rdf file, 
I'm curious to see if this will work on your system. I compile and execute 
the attached code from within the spin-1.4.0/src-examples/ directory. This 
directory only contains the "org" directory and the "kennedysSPIN.rdf" file 
which is also attached.

Thanks a lot,

Wim


Op maandag 22 december 2014 01:15:46 UTC+1 schreef Holger Knublauch:
>
>  
>
> On 12/19/2014 23:06, Wim wrote:
>  
> Hi Mark,
>
> thanks for your time.
>
> In fact I've tracked down the problem using the examples from the SPIN 
> distribution: the problem seems to occur because my ontologies are 
> importing both owrl-all and spl. 
> You can verify this easily: download the KennedysSPIN ontology and add :
>
>      <owl:imports rdf:resource="http://spinrdf.org/spl"; 
> <http://spinrdf.org/spl>/> 
>     <owl:imports rdf:resource="http://topbraid.org/spin/owlrl-all"; 
> <http://topbraid.org/spin/owlrl-all>/>
>  
> If you now run KennedysInferencingAndConstraintsExample.java (modified so 
> it reads the local KennedysSPIN file), it will fail.
>  
>
> Hi Wim,
>
> I have not been able to reproduce this problem yet. The error looks like 
> it failed to parse some SPARQL query. The online version of owlrl uses the 
> text-based SPIN syntax with sp:text, and in order to parse those, it needs 
> certain prefixes to be visible. However, even if I make the modifications 
> you suggest, it still seems to work OK. Instead of modifying the 
> kennedysSPIN file, I have added the owl:imports triples manually (which 
> should have the same effect):
>
> public class KennedysInferencingAndConstraintsExample {
>
>     public static void main(String[] args) {
>         
>         // Initialize system functions and templates
>         SPINModuleRegistry.get().init();
>
>         // Load main file
>         Model baseModel = ModelFactory.createDefaultModel();
>         baseModel.read("http://topbraid.org/examples/kennedysSPIN"; 
> <http://topbraid.org/examples/kennedysSPIN>);
>         baseModel.add(ResourceFactory.createResource(
> "http://topbraid.org/examples/kennedysSPIN"; 
> <http://topbraid.org/examples/kennedysSPIN>),
>                 OWL.imports,
>                 ResourceFactory.createResource(
> "http://topbraid.org/spin/owlrl"; <http://topbraid.org/spin/owlrl>));
>         baseModel.add(ResourceFactory.createResource(
> "http://topbraid.org/examples/kennedysSPIN"; 
> <http://topbraid.org/examples/kennedysSPIN>),
>                 OWL.imports,
>                 ResourceFactory.createResource(SPL.BASE_URI));
>         
>         // Create OntModel with imports
> ...
>
> Despite this change, it still works fine. Could you try to step-by-step 
> narrow down what is different in your scenario? I can see you use an 
> ontpolicy file, which is not used by the default example code.
>
> Thanks
> Holger
>
>
>  
> Is this a bug? Would there be a simple workaround? Any idea why this only 
> fails using the SPIN API and not in TBC?
>
> Thanks a lot for your help,
>
> Wim
>
>
>
> Op donderdag 18 december 2014 21:35:50 UTC+1 schreef Mark Graham: 
>>
>> Hi Wim, 
>>
>>  Thanks for choosing our TopBraid product. Our development team has 
>> reviewed this issue and here are the recommended steps to address your 
>> question.
>>
>>  Please use the code from 
>> http://www.topquadrant.com/repository/spin/org/topbraid/spin/1.4.0/ to 
>> do the following steps - 
>> - Run inferences(org.topbraid.spin.inference.SPINInferences.java) on your 
>> model.
>> - Add the triples generated from the inferences to a model.
>> - Run the constraints(org.topbraid.spin.constraints.SPINConstraints.java) 
>> on the model containing the SPIN inferences.
>>  
>>  
>>  
>>  Thanks,
>> Mark
>>
>>
>> Mark Graham
>> TopQuadrant Support
>>
>>
>>   
>> On Thu, Dec 18, 2014 at 8:20 AM, Wim <[email protected]> wrote: 
>>>
>>> Hello,
>>>
>>> I'm trying to do the following:
>>>  1) read an ontology (and all its imports), generate all inferences
>>>  2) show all constraint violations.
>>>
>>> With TBC SE, I can do this without a problem: I just open the ontology, 
>>> generate the inferences, and check the constraint problems.
>>>
>>> However if I do the same with the SPIN API, only the first step 
>>> succeeds. SPINConstraints.check throws a QueryParseException. See full 
>>> stack trace:
>>> http://pastebin.com/r85LbAVg
>>>
>>> This is my code, based on your examples:
>>> http://pastebin.com/pvhA0Q1n
>>>
>>> Strangely, if I first use TBC to export everything (all ontologies + 
>>> inference graph) into a single file, and apply the CheckConstraints.java 
>>> example, it works as expected.
>>> However if I use the RunInferences.java example to generate the 
>>> inferences and store everything in one file (as is done in my code 
>>> mentioned above, after the exception is thrown), the CheckConstraints.java 
>>> example fails again. There's a little more diagnostics now, apparently it 
>>> fails for some "spl" function: http://pastebin.com/WeXfhPa6
>>> If I remove this spl function, it fails on another spl function, and so 
>>> on. 
>>>
>>> I use an ont-policy.rdf file to control which 
>>> spl.spin.rdf/spin.rdf/sp.rfd/... files are used by the script. I've tried 
>>> to use the RDF files that can be resolved online, those that came with TBC, 
>>> and those that are part of the spinapi jar file. All show the same error.
>>>
>>> To run the inferences and constraint checks I will continue to use TBC, 
>>> but I'd also like to do this in an automated way via SPIN API. 
>>>
>>> Any idea what's going wrong?
>>>
>>> Thanks a lot for your help,
>>>
>>> Wim
>>>  -- 
>>> -- You received this message because you are subscribed to the Google
>>> Group "TopBraid Suite Users", the topics of which include Enterprise 
>>> Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, TopBraid 
>>> Insight, SPARQLMotion, SPARQL Web Pages and SPIN.
>>> To post to this group, send email to
>>> [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/topbraid-users?hl=en
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "TopBraid Suite Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>   -- 
> -- You received this message because you are subscribed to the Google
> Group "TopBraid Suite Users", the topics of which include Enterprise 
> Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, TopBraid 
> Insight, SPARQLMotion, SPARQL Web Pages and SPIN.
> To post to this group, send email to
> [email protected] <javascript:>
> To unsubscribe from this group, send email to
> [email protected] <javascript:>
> For more options, visit this group at
> http://groups.google.com/group/topbraid-users?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "TopBraid Suite Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  

-- 
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary 
Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Insight, 
SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
package org.topbraid.spin.examples;

import java.util.List;

import org.topbraid.spin.constraints.ConstraintViolation;
import org.topbraid.spin.constraints.SPINConstraints;
import org.topbraid.spin.inference.SPINInferences;
import org.topbraid.spin.system.SPINLabels;
import org.topbraid.spin.system.SPINModuleRegistry;
import org.topbraid.spin.util.JenaUtil;

import com.hp.hpl.jena.ontology.OntDocumentManager;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;


/**
 * Loads the Kennedys SPIN ontology and runs inferences and then
 * constraint checks on it.
 * 
 * @author Holger Knublauch
 */
public class KennedysInferencingAndConstraintsExample {

	public static void main(String[] args) {
		
		// Initialize system functions and templates
		SPINModuleRegistry.get().init();

		// Load main file
		Model baseModel = ModelFactory.createDefaultModel();
		baseModel.read("file:./kennedysSPIN.rdf");
		
		// Create OntModel with imports
		OntModel ontModel = JenaUtil.createOntologyModel(OntModelSpec.OWL_MEM,baseModel);
		
		// Create and add Model for inferred triples
		Model newTriples = ModelFactory.createDefaultModel();
		ontModel.addSubModel(newTriples);

		// Register locally defined functions
		SPINModuleRegistry.get().registerAll(ontModel, null);

		// Run all inferences
		SPINInferences.run(ontModel, newTriples, null, null, false, null);
		System.out.println("Inferred triples: " + newTriples.size());
                
		// Run all constraints
		List<ConstraintViolation> cvs = SPINConstraints.check(ontModel, null);
		System.out.println("Constraint violations:");
		for(ConstraintViolation cv : cvs) {
			System.out.println(" - at " + SPINLabels.get().getLabel(cv.getRoot()) + ": " + cv.getMessage());
		}

	}
}

Attachment: kennedysSPIN.rdf
Description: application/rdf

Reply via email to