Closed mariadelcarmen closed 11 years ago
Well, I changed the OPPL and OWLAPI versions I was using. Now I do not have the above problem anymore. However, I new problem showed up:
.....
OPPLScript script = opplParser.parse(problematicPattern);
PatternModel patternModel = factoryOpplPattern.getPatternFactory().createPatternModel(script);
if (patternModel != null) {
List<OWLAxiomChange> newAxioms = new ArrayList<OWLAxiomChange>();
InstantiatedPatternModel ip = factoryOpplPattern.getPatternFactory().createInstantiatedPatternModel(patternModel,new QuickFailRuntimeExceptionHandler());
for (Variable v : patternModel.getInputVariables()) {
ip.instantiate(v, manager.getOWLDataFactory().getOWLClass(IRI.create("http://domain.owl#AdenoAdenoma")));
}
NonClassPatternExecutor ncpe = new NonClassPatternExecutor(ip,ontology, manager, manager.getOntologyDocumentIRI(ontology),new QuickFailRuntimeExceptionHandler());
newAxioms.addAll(ncpe.visit(patternModel));
...
}
I get the following exception performing ncpe.visit(patternModel)
:
Exception in thread "main" java.lang.ClassCastException: org.coode.oppl.ConstraintSystem cannot be cast to org.coode.patterns.PatternConstraintSystem
at org.coode.patterns.PatternModel.getConstraintSystem(PatternModel.java:483)
at org.coode.patterns.PatternModel$ClassPatternDetector.<init>(PatternModel.java:119)
at org.coode.patterns.PatternModel.isClassPattern(PatternModel.java:704)
at org.coode.patterns.InstantiatedPatternModel.isClassPattern(InstantiatedPatternModel.java:430)
at org.coode.patterns.InstantiatedPatternModel.extractBindingNodes(InstantiatedPatternModel.java:279)
at org.coode.patterns.PatternActionFactory.createChange(PatternActionFactory.java:111)
at org.coode.patterns.NonClassPatternExecutor.visit(NonClassPatternExecutor.java:71)
at test.oppl.PatternExecution.executionNotWorkingWithReasoner(PatternExecution.java:244)
at test.oppl.PatternExecution.main(PatternExecution.java:1353)
It seems that I cannot really execute an OPPL pattern through an OPPL script.
Thanks for the test case, I'm going to try and replicate it.
I can replicate your issue and correct it (in the sense that I do not get exceptions) this way.
Note that there are two issues:
public static void main(String[] args) throws OWLOntologyCreationException {
String patternCode = "?adenoma:CLASS[subClassOf Adenoma]\nBEGIN\nADD !item instanceOf HistopathologyReport and hasFinding some ?adenoma\nEND;";
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology();
OWLDataFactory df = manager.getOWLDataFactory();
// initializing the ontology to be able to parse the query
manager.addAxiom(ontology, df.getOWLDeclarationAxiom(df.getOWLClass(IRI.create("urn:HistopathologyReport")), new HashSet<OWLAnnotation>(Arrays.asList(df.getOWLAnnotation(df.getRDFSLabel(), df.getOWLLiteral("HistopathologyReport"))))));
OWLClass adenoma = df.getOWLClass(IRI.create("urn:Adenoma"));
manager.addAxiom(ontology, df.getOWLDeclarationAxiom(adenoma, new HashSet<OWLAnnotation>(Arrays.asList(df.getOWLAnnotation(df.getRDFSLabel(), df.getOWLLiteral("Adenoma"))))));
manager.addAxiom(ontology, df.getOWLDeclarationAxiom(df.getOWLObjectProperty(IRI.create("urn:hasFinding")), new HashSet<OWLAnnotation>(Arrays.asList(df.getOWLAnnotation(df.getRDFSLabel(), df.getOWLLiteral("hasFinding"))))));
// the exact reasoner does not matter here
OWLReasoner reasoner = new JFactFactory().createReasoner(ontology);
//bit that needs changing
OPPLPatternParser patternParser = new OPPLPatternParser(new PatternModelFactory(ontology, manager, reasoner), new SystemErrorEcho(), new SimpleSymbolTableFactory(manager));
OPPLScript script = patternParser.parse(patternCode);
PatternModel patternModel = patternParser.getOPPLPatternFactory().createPatternModel(script);
List<OWLAxiomChange> newAxioms = new ArrayList<OWLAxiomChange>();
InstantiatedPatternModel ip = patternParser.getOPPLPatternFactory().createInstantiatedPatternModel(patternModel, new QuickFailRuntimeExceptionHandler());
for (Variable v : patternModel.getInputVariables()) {
ip.instantiate(v, adenoma);
}
NonClassPatternExecutor ncpe = new NonClassPatternExecutor(ip, ontology, manager, manager.getOntologyDocumentIRI(ontology), new QuickFailRuntimeExceptionHandler());
newAxioms.addAll(ncpe.visit(patternModel));
}
I still had to download all the code of the libraries from github and recompile because I had some odd exceptions with those downloaded from http://sourceforge.net/projects/oppl2/files/. Now this works perfect, Thanks a lot!
On 24 Oct 2013 10:23, "mariadelcarmen" notifications@github.com wrote:
I still had to download all the code of the libraries from github and recompile because I had some odd exceptions with those downloaded from http://sourceforge.net/projects/oppl2/files/. Now this works perfect, Thanks a lot!
Yeah we need to sort the maven build and make a release. I.
— Reply to this email directly or view it on GitHub.
I am trying to instantiate and execute an OPPL pattern like this:
?adenoma:CLASS[subClassOf Adenoma] BEGIN ADD !item instanceOf HistopathologyReport and hasFinding some ?adenoma END;
I try to parser it with:
But I get
"No reasoner selected at line 1 position 14"
Since I do not see a way to createorg.coode.patterns.ParserFactory
with a reasoner, a tried this way:But I got
"Recognition exception when parsing token: BEGIN line 2 position 0 unexpected token code 83"
and the result of variablescript
is null. It seems that I cannot parser the pattern as an OPPLScript, since it does not have a SELECT action. Then, how could I get the PatternModel for my OPPL pattern with the variable scope defined using a reasoner?