Skip to content

Commit 612661f

Browse files
committed
fix(search2): Fall back to raw @vocab value when no vocab prefix is mapped
1 parent 017bc96 commit 612661f

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎whelk-core/src/main/groovy/whelk/search2/Disambiguate.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static Property getPropertyByKey(String key, JsonLd jsonLd) {
102102

103103
public static Property getPropertyByKey(String key, JsonLd jsonLd, List<String> nsPrecedenceOrder) {
104104
Map<String, Map<String, Object>> vocab = jsonLd.vocabIndex;
105-
String vocabPrefix = jsonLd.getVocabPrefix();
105+
String vocabPrefix = ResourceLookup.getVocabPrefix(jsonLd);
106106

107107
String[] keyParts = key.split(":");
108108
boolean isPrefixed = keyParts.length == 2;

‎whelk-core/src/main/groovy/whelk/search2/ResourceLookup.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public static ResourceLookup load(Whelk whelk) {
3939
public ResourceLookup(VocabMappings vocabMappings) {
4040
this(vocabMappings, new ExternalMappings(Map.of()));
4141
}
42+
43+
public static String getVocabPrefix(JsonLd jsonLd) {
44+
try {
45+
return jsonLd.getVocabPrefix();
46+
} catch (IllegalStateException e) {
47+
return (String) jsonLd.context.get(JsonLd.VOCAB_KEY);
48+
}
49+
}
4250

4351
public record VocabMappings(
4452
/*
@@ -91,7 +99,7 @@ static VocabMappings load(Whelk whelk) {
9199
private static VocabMappings getMappings(Whelk whelk) {
92100
var jsonLd = whelk.getJsonld();
93101
var vocab = jsonLd.vocabIndex;
94-
var vocabPrefix = jsonLd.getVocabPrefix();
102+
var vocabPrefix = getVocabPrefix(jsonLd);
95103

96104
Map<String, Map<String, Set<String>>> properties = new HashMap<>();
97105
Map<String, Map<String, Set<String>>> classes = new HashMap<>();

0 commit comments

Comments
 (0)