Skip to content

Commit

Permalink
move shortform to the linker
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesamcl committed Nov 8, 2024
1 parent f026c2b commit c58e873
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 51 deletions.
62 changes: 18 additions & 44 deletions dataload/linker/src/main/java/LinkerPass2.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ private static void writeEntityArray(JsonReader jsonReader, JsonWriter jsonWrite

EntityDefinitionSet defOfThisEntity = pass1Result.iriToDefinitions.get(entityIri);

String curie = null;
if(defOfThisEntity.definingDefinitions.size() > 0) {
// always use the defining ontology's curie, as the defining
// ontology knows the base URI and we might not
//
curie = defOfThisEntity.definingDefinitions.iterator().next().curie.getAsString();
}

while(jsonReader.peek() != JsonToken.END_OBJECT) {

String name = jsonReader.nextName();
Expand All @@ -159,22 +167,23 @@ private static void writeEntityArray(JsonReader jsonReader, JsonWriter jsonWrite
}

if(name == "curie") {
if(defOfThisEntity.definingDefinitions.size() > 0) {
// always use the defining ontology's curie, as the defining
// ontology knows the base URI and we might not
//
com.google.gson.internal.Streams.write(
defOfThisEntity.definingDefinitions.iterator().next().curie,
jsonWriter);
continue;
if(curie != null) {
// use the defining ontology curie
jsonWriter.value(curie);
} else {
// fallback to using the curie we already have
// fallthrough to using the curie from rdf2json
curie = jsonReader.nextString();
jsonWriter.value(curie);
}
continue;
}

CopyJsonGatheringStrings.copyJsonGatheringStrings(jsonReader, jsonWriter, stringsInEntity);
}

jsonWriter.name("shortForm");
jsonWriter.value(curie.replaceFirst(":", "_"));

if(defOfThisEntity != null) {

jsonWriter.name(IS_DEFINING_ONTOLOGY.getText());
Expand Down Expand Up @@ -452,39 +461,4 @@ private static class CurieMapResult {
public String url;
public String source;
}

private static void processShortFormObject(JsonReader jsonReader, JsonWriter jsonWriter, LinkerPass1.LinkerPass1Result pass1Result, String entityIri) throws IOException {
jsonReader.beginObject();
JsonObject shortFormObject = new JsonObject();

while (jsonReader.peek() != JsonToken.END_OBJECT) {
String shortFormFieldName = jsonReader.nextName();
if (shortFormFieldName.equals("type")) {
JsonArray typeArray = new JsonArray();
jsonReader.beginArray();
while (jsonReader.peek() != JsonToken.END_ARRAY) {
typeArray.add(jsonReader.nextString());
}
jsonReader.endArray();
shortFormObject.add("type", typeArray);
} else if (shortFormFieldName.equals("value")) {
String shortFormValue = jsonReader.nextString();
// Modify the value attribute
shortFormValue = getProcessedCurieValue(pass1Result, entityIri).replace(":", "_");
shortFormObject.addProperty("value", shortFormValue);
}
}
jsonReader.endObject();

// Write the modified short form object
jsonWriter.beginObject();
jsonWriter.name("type");
jsonWriter.beginArray();
for (JsonElement typeElement : shortFormObject.getAsJsonArray("type")) {
jsonWriter.value(typeElement.getAsString());
}
jsonWriter.endArray();
jsonWriter.name("value").value(shortFormObject.get("value").getAsString());
jsonWriter.endObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ private String urlToFilename(String url) {
HierarchicalParentsAnnotator.annotateHierarchicalParents(this); // must run after RelatedAnnotator
AncestorsAnnotator.annotateAncestors(this);
HierarchyMetricsAnnotator.annotateHierarchyMetrics(this); // must run after HierarchicalParentsAnnotator
ShortFormAnnotator.annotateShortForms(this);
CurieAnnotator.annotateCuries(this);
DefinitionAnnotator.annotateDefinitions(this);
SynonymAnnotator.annotateSynonyms(this);
ReifiedPropertyAnnotator.annotateReifiedProperties(this);
OntologyMetadataAnnotator.annotateOntologyMetadata(this);
HierarchyFlagsAnnotator.annotateHierarchyFlags(this); // must run after DirectParentsAnnotator and HierarchicalParentsAnnotator
IsObsoleteAnnotator.annotateIsObsolete(this);
LabelAnnotator.annotateLabels(this); // must run after ShortFormAnnotator
LabelAnnotator.annotateLabels(this); // must run after CurieAnnotator
ConfigurablePropertyAnnotator.annotateConfigurableProperties(this);
PreferredRootsAnnotator.annotatePreferredRoots(this);
DisjointWithAnnotator.annotateDisjointWith(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import uk.ac.ebi.rdf2json.annotators.helpers.OntologyBaseUris;
import uk.ac.ebi.rdf2json.properties.PropertyValueLiteral;

public class ShortFormAnnotator {
private static final Logger logger = LoggerFactory.getLogger(ShortFormAnnotator.class);
public class CurieAnnotator {
private static final Logger logger = LoggerFactory.getLogger(CurieAnnotator.class);

public static void annotateShortForms(OntologyGraph graph) {
public static void annotateCuries(OntologyGraph graph) {

long startTime3 = System.nanoTime();

Expand Down Expand Up @@ -41,7 +41,7 @@ public static void annotateShortForms(OntologyGraph graph) {
}
}
long endTime3 = System.nanoTime();
logger.info("annotate short forms: {}", ((endTime3 - startTime3) / 1000 / 1000 / 1000));
logger.info("annotate curies: {}", ((endTime3 - startTime3) / 1000 / 1000 / 1000));


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Set<String> getLabelProperties(OntologyGraph graph) {
}

public static void annotateLabels(OntologyGraph graph) {
collateProperties(graph, "label", getLabelProperties(graph), List.of("shortForm"));
collateProperties(graph, "label", getLabelProperties(graph), List.of("curie"));
}

private static void collateProperties(OntologyGraph graph, String destProp, Collection<String> sourceProps, Collection<String> fallbackProps) {
Expand Down

0 comments on commit c58e873

Please sign in to comment.