Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(search2): Ignore abstract terms in disambiguation #1563

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions whelk-core/src/main/groovy/whelk/search2/Disambiguate.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ private void setAliasMappings(Whelk whelk) {
var vocab = jsonLd.vocabIndex;

vocab.forEach((termKey, termDefinition) -> {
if (isAbstract(termDefinition)) {
return;
}
if (isSystemVocabTerm(termDefinition, jsonLd)) {
if (isClass(termDefinition, jsonLd)) {
addAllMappings(termKey, classAliasMappings, ambiguousClassAliases, whelk);
Expand Down Expand Up @@ -174,7 +177,7 @@ private void addEquivTermMappings(String termKey, Map<String, String> aliasMappi
});
}

private static boolean isSystemVocabTerm(Map<?, ?> termDefinition, JsonLd jsonLd) {
private static boolean isSystemVocabTerm(Map<String, Object> termDefinition, JsonLd jsonLd) {
return get(termDefinition, List.of(IS_DEFINED_BY, ID_KEY), "")
.equals(jsonLd.context.get(VOCAB_KEY));
}
Expand All @@ -183,11 +186,11 @@ private static boolean isMarc(String termKey) {
return termKey.startsWith("marc:");
}

private static boolean isClass(Map<?, ?> termDefinition, JsonLd jsonLd) {
private static boolean isClass(Map<String, Object> termDefinition, JsonLd jsonLd) {
return getTypes(termDefinition).stream().anyMatch(type -> jsonLd.isSubClassOf((String) type, "Class"));
}

private static boolean isEnum(Map<?, ?> termDefinition, JsonLd jsonLd) {
private static boolean isEnum(Map<String, Object> termDefinition, JsonLd jsonLd) {
return getTypes(termDefinition).stream()
.map(String.class::cast)
.flatMap(type -> Stream.concat(jsonLd.getSuperClasses(type).stream(), Stream.of(type)))
Expand All @@ -197,18 +200,22 @@ private static boolean isEnum(Map<?, ?> termDefinition, JsonLd jsonLd) {
.anyMatch(jsonLd::isVocabTerm);
}

private static boolean isProperty(Map<?, ?> termDefinition) {
private static boolean isProperty(Map<String, Object> termDefinition) {
return isObjectProperty(termDefinition) || isDatatypeProperty(termDefinition);
}

public static boolean isObjectProperty(Map<?, ?> termDefinition) {
public static boolean isObjectProperty(Map<String, Object> termDefinition) {
return getTypes(termDefinition).stream().anyMatch(OBJECT_PROPERTY::equals);
}

private static boolean isDatatypeProperty(Map<?, ?> termDefinition) {
private static boolean isDatatypeProperty(Map<String, Object> termDefinition) {
return getTypes(termDefinition).stream().anyMatch(DATATYPE_PROPERTY::equals);
}

private static boolean isAbstract(Map<String, Object> termDefinition) {
return (boolean) termDefinition.getOrDefault("abstract", false);
}

private static List<?> getTypes(Map<?, ?> termDefinition) {
return asList(termDefinition.get(JsonLd.TYPE_KEY));
}
Expand Down