-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow creating a node without an explicit ID.
This commit makes it possible to use a "create <nodetype>" command without specifying an explicit ID, just a label: create class "my new class" This is equivalent to: create class AUTOID:<random_value> "my new class" This change is accompanied by several refactoring changes: * The IEntityLabelResolver interface (which gains two more methods to support the feature above) is renamed to ILabelResolver. * The ParseTree2ChangeVisitor class is made less flexible, as it is only ever intended to be used internally by the KGCLReader class, not by client code.
- Loading branch information
Showing
12 changed files
with
183 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/main/java/org/incenp/obofoundry/kgcl/SimpleLabelResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* KGCL-Java - KGCL library for Java | ||
* Copyright © 2024 Damien Goutte-Gattat | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the Gnu General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.incenp.obofoundry.kgcl; | ||
|
||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
/** | ||
* A basic implementation of the {@link ILabelResolver} interface. | ||
* <p> | ||
* This implementation is backed up by a simple dictionary mapping labels to | ||
* their corresponding identifiers. When a new ID is requested (with | ||
* {@link #getNewId(String)}), it mints a temporary ID suitable for use with the | ||
* {@link org.incenp.obofoundry.kgcl.AutoIDAllocator} class. | ||
*/ | ||
public class SimpleLabelResolver implements ILabelResolver { | ||
|
||
private HashMap<String, String> idMap = new HashMap<String, String>(); | ||
|
||
@Override | ||
public String resolve(String label) { | ||
return idMap.get(label); | ||
} | ||
|
||
@Override | ||
public String getNewId(String label) { | ||
String newId = AutoIDAllocator.AUTOID_BASE_IRI + UUID.randomUUID().toString(); | ||
idMap.put(label, newId); | ||
return newId; | ||
} | ||
|
||
@Override | ||
public void add(String label, String identifier) { | ||
idMap.put(label, identifier); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.