I am trying to parse a class expression in Manchester syntax written using rdfs:label, just like one would enter in Protégé with view set to "render by label", so something like Pizza and not(hasTopping some 'Meat topping') instead of Pizza and not(hasTopping some MeatTopping).
I can't find a way to do that. I got some inspiration from the code at OWLAPI : "ParserException" while converting String to Class Expression using ManchesterOWLSyntaxParser, and I tried using different ShortFormProviders : ShortFormFromRDFSLabelAxiomListProvider, AnnotationValueShortFormProvider, ManchesterOWLSyntaxPrefixNameShortFormProvider, but the parser would always complain that it does recognize 'Meat topping' as a class name.
I also saw ManchesterOWLSyntaxEditorParser but it is deprecated.
What is the correct way to parse an OWLClassExpression in Manchester syntax that uses rdfs:label as class names ?
Thanks
Here are my attempts:
ManchesterOWLSyntaxParser manchesterParser = OWLManager.createManchesterParser();
// ManchesterOWLSyntaxEditorParser manchesterParser = new ManchesterOWLSyntaxEditorParser(df, null);
String toParse = "Pizza\n"
+ " and (not (hasTopping some 'Meat Topping'))";
manchesterParser.setDefaultOntology(ontology); // my ontology
ShortFormEntityChecker checker = new ShortFormEntityChecker(getShortFormProvider(manager, ontology));
manchesterParser.setOWLEntityChecker(checker);
OWLClassExpression expr = manchesterParser.parseClassExpression(toParse);
private static BidirectionalShortFormProvider getShortFormProvider(OWLOntologyManager manager, OWLOntology ont) {
Set<OWLOntology> ontologies = manager.getOntologies(); // my OWLOntologyManager
// all my attempts to use different short form providers :
// ShortFormProvider sfp = new ManchesterOWLSyntaxPrefixNameShortFormProvider(ont);
ShortFormProvider sfp = new SimpleShortFormProvider();
/*
ShortFormFromRDFSLabelAxiomListProvider sfp = new ShortFormFromRDFSLabelAxiomListProvider(
Arrays.asList(new String[] {"en"}),
ont.axioms().toList(),
new SimpleShortFormProvider()
);
*/
/*
OWLAnnotationProperty rdfsLabelProp = manager.getOWLDataFactory().getOWLAnnotationProperty("http://www.w3.org/2000/01/rdf-schema#label");
AnnotationValueShortFormProvider sfp = new AnnotationValueShortFormProvider(
Collections.singletonList(rdfsLabelProp),
new HashMap<OWLAnnotationProperty, List<String>>() {{
put(rdfsLabelProp, Arrays.asList(new String[] {"en"}));
}},
manager
);
*/
BidirectionalShortFormProvider shortFormProvider = new BidirectionalShortFormProviderAdapter(
ontologies, sfp);
return shortFormProvider;
}
EDIT
The problem comes from the fact that labels contains space characters. The ShortFormProvider correctly knows and understands the short form Meat Topping, but what the Manchester parser passes to it to resolve the short name is 'Meat Topping', with the quotes included. Is that a bug ?
EDIT 2
I can edit a class expression in Protégé using labels:
When I save it, I got this:
Class: <http://www.semanticweb.org/thomas/ontologies/2023/7/untitled-ontology-165#VegetarianPizza>
EquivalentTo:
<http://www.semanticweb.org/thomas/ontologies/2023/7/untitled-ontology-165#Pizza>
and (not (<http://www.semanticweb.org/thomas/ontologies/2023/7/untitled-ontology-165#hasTopping> some <http://www.semanticweb.org/thomas/ontologies/2023/7/untitled-ontology-165#MeatTopping>))
Obviously, the serialization does not use the labels, it just uses the URI or local names.
I don't want to parse class expressions as they are serialized, I want to parse them as they are edited in Protégé. Some code somewhere knows how to do that, because Protégé does it. I just can't figure out how to make it work. If you know where in Protégé the class expression editor works, maybe that could help.
