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

Factor out PropertyLike #1543

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@

import static whelk.JsonLd.TYPE_KEY;

public sealed interface InvalidKey {
record UnrecognizedKey(String key) implements InvalidKey {}
record AmbiguousKey(String key) implements InvalidKey {}
public sealed interface InvalidKey extends PropertyLike {
record UnrecognizedKey(String name) implements InvalidKey {}
record AmbiguousKey(String name) implements InvalidKey {}

String key();

default Map<String, Object> getDefinition() {
default Map<String, Object> definition() {
var m = new LinkedHashMap<String, Object>();
m.put(TYPE_KEY, "_Invalid");
m.put("label", key());
m.put("label", name());
return m;
}
}
4 changes: 1 addition & 3 deletions whelk-core/src/main/groovy/whelk/search2/querytree/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public Path(List<Object> path) {
@Override
public String toString() {
return path.stream()
.map(x -> x instanceof Property p
? p.name() :
(x instanceof InvalidKey i ? i.key() : (String) x))
.map(x -> x instanceof PropertyLike p ? p.name() : (String) x)
.map(this::substitute)
.collect(Collectors.joining("."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ public Map<String, Object> toSearchMapping(QueryTree qt, Map<String, String> non
var propertyChainAxiom = new LinkedList<>();

for (int i = getPath().size() - 1; i >= 0; i--) {
if (getPath().get(i) instanceof Property property) {
if (getPath().get(i) instanceof PropertyLike property) {
propertyChainAxiom.push(i > 0 && getPath().get(i - 1).equals(JsonLd.REVERSE_KEY)
? Map.of("inverseOf", property.definition())
: property.definition());
} else if (getPath().get(i) instanceof InvalidKey invalid) {
propertyChainAxiom.push(invalid.getDefinition());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;

import static whelk.search2.Disambiguate.RDF_TYPE;

public class Property {
public class Property implements PropertyLike {
public enum DomainCategory {
ADMIN_METADATA,
WORK,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package whelk.search2.querytree;

import java.util.Map;

public interface PropertyLike {
String name();
Map<String, Object> definition();
}