-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'support-literal-mappings'
- Loading branch information
Showing
26 changed files
with
439 additions
and
175 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
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
80 changes: 80 additions & 0 deletions
80
core/src/main/java/org/incenp/obofoundry/sssom/Validator.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,80 @@ | ||
/* | ||
* SSSOM-Java - SSSOM 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.sssom; | ||
|
||
import org.incenp.obofoundry.sssom.model.EntityType; | ||
import org.incenp.obofoundry.sssom.model.Mapping; | ||
|
||
/** | ||
* Helper class to validate MappingSet and Mapping objects. | ||
* <p> | ||
* This class is primarily intended to be used internally by the parsers for | ||
* post-parsing validation, to ensure that the parsed objects are compliant with | ||
* the requirements from the SSSOM specification. However it may also be used | ||
* independently of the parsers, for example to validate a set that was | ||
* constructed <em>ex nihilo</em>. | ||
*/ | ||
public class Validator { | ||
|
||
public static final String MISSING_SUBJECT_LABEL = "Missing subject_label"; | ||
public static final String MISSING_SUBJECT_ID = "Missing subject_id"; | ||
public static final String MISSING_OBJECT_LABEL = "Missing object_label"; | ||
public static final String MISSING_OBJECT_ID = "Missing object_id"; | ||
public static final String MISSING_PREDICATE = "Missing predicate_id"; | ||
public static final String MISSING_JUSTIFICATION = "Missing mapping_justification"; | ||
|
||
/** | ||
* Validates an individual mapping. This method checks that the slots that are | ||
* required by the specification are present and non-empty. | ||
* | ||
* @param mapping The mapping to validate. | ||
* @return An error message if the mapping is invalid, otherwise {@code null}. | ||
*/ | ||
public String validate(Mapping mapping) { | ||
if ( mapping.getSubjectType() == EntityType.RDFS_LITERAL ) { | ||
if ( mapping.getSubjectLabel() == null || mapping.getSubjectLabel().isEmpty() ) { | ||
return MISSING_SUBJECT_LABEL; | ||
} | ||
} else { | ||
if ( mapping.getSubjectId() == null || mapping.getSubjectId().isEmpty() ) { | ||
return MISSING_SUBJECT_ID; | ||
} | ||
} | ||
|
||
if ( mapping.getObjectType() == EntityType.RDFS_LITERAL ) { | ||
if ( mapping.getObjectLabel() == null || mapping.getObjectLabel().isEmpty() ) { | ||
return MISSING_OBJECT_LABEL; | ||
} | ||
} else { | ||
if ( mapping.getObjectId() == null || mapping.getObjectId().isEmpty() ) { | ||
return MISSING_OBJECT_ID; | ||
} | ||
} | ||
|
||
if ( mapping.getPredicateId() == null || mapping.getPredicateId().isEmpty() ) { | ||
return MISSING_PREDICATE; | ||
} | ||
|
||
if ( mapping.getMappingJustification() == null || mapping.getMappingJustification().isEmpty() ) { | ||
return MISSING_JUSTIFICATION; | ||
} | ||
|
||
return null; | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
core/src/main/java/org/incenp/obofoundry/sssom/compatibility/LiteralProfileConverter.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,66 @@ | ||
/* | ||
* SSSOM-Java - SSSOM 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.sssom.compatibility; | ||
|
||
import java.util.Map; | ||
|
||
import org.incenp.obofoundry.sssom.IYAMLPreprocessor; | ||
import org.incenp.obofoundry.sssom.SSSOMFormatException; | ||
|
||
/** | ||
* A YAML preprocessor to convert <code>literal*</code> slots. | ||
* <p> | ||
* For a time, the SSSOM specification half-defined a "literal profile", | ||
* intended for mappings between a literal and an entity. That profile has | ||
* several literal-specific slots. In SSSOM 1.0, this profile has been removed | ||
* and replaced by a convention that literal subjects are represented by storing | ||
* the literal in the <code>subject_label</code> slot and setting the | ||
* <code>subject_type</code> slot to <code>sssom literal</code>. | ||
*/ | ||
public class LiteralProfileConverter implements IYAMLPreprocessor { | ||
|
||
@Override | ||
public void process(Map<String, Object> rawMap) throws SSSOMFormatException { | ||
if ( rawMap.containsKey("literal") && !rawMap.containsKey("subject_label") ) { | ||
rawMap.put("subject_label", rawMap.get("literal")); | ||
rawMap.put("subject_type", "rdfs literal"); | ||
|
||
Object o = rawMap.get("literal_source"); | ||
if ( o != null ) { | ||
rawMap.put("subject_source", o); | ||
} | ||
|
||
o = rawMap.get("literal_source_version"); | ||
if ( o != null ) { | ||
rawMap.put("subject_source_version", o); | ||
} | ||
|
||
o = rawMap.get("literal_preprocessing"); | ||
if ( o != null ) { | ||
rawMap.put("subject_preprocessing", o); | ||
} | ||
|
||
rawMap.remove("literal"); | ||
rawMap.remove("literal_datatype"); | ||
rawMap.remove("literal_source"); | ||
rawMap.remove("literal_source_version"); | ||
rawMap.remove("literal_preprocessing"); | ||
} | ||
} | ||
} |
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.