From bc69fd9cd219bd959c77a02ea6d60604d9f33c77 Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Wed, 13 Mar 2024 12:41:51 +0000 Subject: [PATCH] Add more tests for the language-based label selection. Add a couple of more tests to check that, when looking for an existing label, we only select the correct label (with or without a language tag) based on whether a language tag was explicitly specified in the original KGCL command. --- .../kgcl/DirectOWLTranslatorTest.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/core/src/test/java/org/incenp/obofoundry/kgcl/DirectOWLTranslatorTest.java b/core/src/test/java/org/incenp/obofoundry/kgcl/DirectOWLTranslatorTest.java index 91c664d..e3c784e 100644 --- a/core/src/test/java/org/incenp/obofoundry/kgcl/DirectOWLTranslatorTest.java +++ b/core/src/test/java/org/incenp/obofoundry/kgcl/DirectOWLTranslatorTest.java @@ -203,6 +203,100 @@ void testNodeRenameExplicitNewDatatype() { testChange(change, expected, null); } + @Test + void testNodeRenameOldLanguageDoesNotSelectLanglessLabel() { + // The pizza ontology does not contain labels without an explicit language tag, + // so we need to craft one. + ontology.getOWLOntologyManager().addAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", null)); + + NodeRename change = new NodeRename(); + setAboutNode(change, "LaReine"); + setValue(change, "LaReine", "en", true); + setValue(change, "TheQueen", "en"); + + ArrayList expected = new ArrayList(); + expected.add(new RemoveAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", "en"))); + expected.add(new AddAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "TheQueen", "en"))); + + testChange(change, expected, null); + } + + @Test + void testNodeRenameNoLanguageTagDoesSelectLanglessLabel() { + // Add langless label + ontology.getOWLOntologyManager().addAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", null)); + + NodeRename change = new NodeRename(); + setAboutNode(change, "LaReine"); + setValue(change, "LaReine", null, true); + setValue(change, "TheQueen", null); + + // All three labels should be renamed, including the langless one. + + ArrayList expected = new ArrayList(); + expected.add(new RemoveAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", "en"))); + expected.add(new RemoveAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", "pt"))); + expected.add(new RemoveAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", null))); + expected.add(new AddAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "TheQueen", "en"))); + expected.add(new AddAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "TheQueen", "pt"))); + expected.add(new AddAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "TheQueen", null))); + + testChange(change, expected, null); + } + + @Test + void testNodeRenameNewLanguageTagDoesNotSelectLanglessLabel() { + // Add langless label + ontology.getOWLOntologyManager().addAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", null)); + + NodeRename change = new NodeRename(); + setAboutNode(change, "LaReine"); + setValue(change, "LaReine", null, true); + setValue(change, "TheQueen", "en"); + + // Since we have an explicit language tag on the new value, only the English + // label should be renamed. + + ArrayList expected = new ArrayList(); + expected.add(new RemoveAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", "en"))); + expected.add(new AddAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "TheQueen", "en"))); + + testChange(change, expected, null); + } + + @Test + void testNodeRenameLanguageTagDoesNotSelectAnotherLangLabel() { + // Remove the English label + ontology.getOWLOntologyManager().removeAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", "en")); + + NodeRename change = new NodeRename(); + setAboutNode(change, "LaReine"); + setValue(change, "LaReine", "en", true); + setValue(change, "TheQueen", "en"); + + // Looking for an English label should not match a label with a different + // language. + testChange(change, null, "Label \"LaReine\" not found on <" + PIZZA_BASE + "LaReine>"); + } + + @Test + void testNodeRenameNewLanguageTagSelectsLanglessLabelIfNoOtherLabelMatches() { + // Remove the English label and adds a langless one + ontology.getOWLOntologyManager().removeAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", "en")); + ontology.getOWLOntologyManager().addAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", null)); + + NodeRename change = new NodeRename(); + setAboutNode(change, "LaReine"); + setValue(change, "LaReine", null, true); + setValue(change, "TheQueen", "en"); + + ArrayList expected = new ArrayList(); + expected.add(new RemoveAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "LaReine", null))); + expected.add(new AddAxiom(ontology, getAnnotation(LABEL_IRI, "LaReine", "TheQueen", "en"))); + + testChange(change, expected, null); + } + @Test void testRejectedNodeRename() { NodeRename change = new NodeRename();