0

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:

class expression screenshot

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.

ThomasFrancart
  • 470
  • 3
  • 13
  • Instead of the `SimpleShortFormProvider` you have to use your custom label based provider. This is easy to implement. In Protege a more generic one for any annotation property being configured has been implemented: https://github.com/protegeproject/protege/blob/master/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/renderer/AnnotationValueShortFormProvider.java - but just for `rdfs:label` you can simplify the code – UninformedUser Aug 22 '23 at 09:12
  • I know I have to replace SimpleShortFormProvider with something else, but my question is precisely how ? this is what I can't get to work. Please see the code commented above to see what I have tried. – ThomasFrancart Aug 22 '23 at 09:43
  • Digging deeper I think the problem arises when labels contains space characters and are enclosed in quotes. – ThomasFrancart Aug 22 '23 at 10:01
  • Please see the question update. The problem is that the manchester parser passes the name including quotes to the ShortFormProvider, e.g. `'Meat Topping'`, instead of `Meat Topping`. Is this a bug or am I doing something completely wrong ? i am using OWLAPI 5.5.0. – ThomasFrancart Aug 22 '23 at 10:16
  • To verify if this is a bug in the parser, try saving an example ontology from protege with a space in the label as Manchester syntax and parse that with OWLAPI as a regular ontology. If the parsing is successful, then the problem is somewhere in the code you're showing; if the parsing fails, then the limit is in the parser itself and it will need to be addressed as a bug. You can raise an issue on the OWLAPI github page for that. – Ignazio Aug 22 '23 at 15:23
  • @Ignazio see EDIT2 in the question. I don't think this is very helpful as the saved file does not contain the labels in class expression, it contains the URI or the local name. I can't prove that the parser works or does not work on such an example. I want to parse class expressions as they are edited in Protégé, not as they are read from a Manchester syntax file. – ThomasFrancart Aug 24 '23 at 15:41
  • I find it quite useful, instead. It means the parser doesn't expect the label inline in the expression, meaning that, to achieve the result you see in Protege, Protege must be creating short form providers able to cope with inline strings. I'm not sure how that's done, but now we know Protege's source code must contain the answer. – Ignazio Aug 24 '23 at 21:04
  • @Ignazio : "Protege must be creating short form providers able to cope with inline strings" : yes this is what I tried. Please take a look at the provided code, in the commented out section, you will see I tried with ShortFormFromRDFSLabelAxiomListProvider and AnnotationValueShortFormProvider. BUT, further debug has shown that the short form provider DOES work (e.g. it can resolve "Meat topping"), but the Manchester parser does not provide it with "Meat topping", but with "'Meat topping'" (quotes included). Problem seems to be in the parser and not in the short form provider. – ThomasFrancart Aug 25 '23 at 07:46
  • Issue submitted at https://github.com/owlcs/owlapi/issues/1111 – ThomasFrancart Aug 25 '23 at 09:24

0 Answers0