Skip to content

Method: hasTermMapping(String)

1: package cz.cvut.kbss.jsonld.serialization.context;
2:
3: import cz.cvut.kbss.jsonld.serialization.model.JsonNode;
4: import cz.cvut.kbss.jsonld.serialization.model.ObjectNode;
5:
6: import java.util.Optional;
7:
8: /**
9: * Represents the {@literal @context} JSON-LD attribute.
10: */
11: public interface JsonLdContext {
12:
13: /**
14: * Registers the specified term mapping in this context.
15: * <p>
16: * Typically, the {@code term} would be Java attribute (field) name and {@code iri} would be the IRI to which this
17: * field is mapped.
18: *
19: * @param term Mapped term
20: * @param iri IRI to which the term is mapped
21: */
22: void registerTermMapping(String term, String iri);
23:
24: /**
25: * Registers the specified term mapping in this context.
26: * <p>
27: * Compared to {@link #registerTermMapping(String, String)}, this method allows registering more complex mapping
28: * like language containers or typed literals.
29: *
30: * @param term Mapped term
31: * @param mappedNode Node to which the term is mapped
32: */
33: void registerTermMapping(String term, ObjectNode mappedNode);
34:
35: /**
36: * Gets the mapping for the specified term (if it exists).
37: *
38: * @param term Term to get mapping for
39: * @return Optional mapping node
40: */
41: Optional<JsonNode> getTermMapping(String term);
42:
43: /**
44: * Checks whether this JSON-LD context contains mapping for the specified term.
45: *
46: * @param term Term to search mapping for
47: * @return {@code true} if a mapping is already defined for the term, {@code false} otherwise
48: */
49: default boolean hasTermMapping(String term) {
50: return getTermMapping(term).isPresent();
51: }
52:
53: /**
54: * Gets the term mapped to the specified identifier (if it exists).
55: * <p>
56: * This method checks term mapping in this context and finds a term that is mapped to the specified identifier.
57: *
58: * @param iri Identifier the term is mapped to
59: * @return Optional mapped term, empty optional if there is no such term mapping
60: */
61: Optional<String> getMappedTerm(String iri);
62:
63: /**
64: * Checks whether this particular JSON-LD context is empty.
65: * <p>
66: * Term mapping inherited from any parent contexts is not considered.
67: *
68: * @return {@code true} if this context is empty, {@code false} otherwise
69: */
70: boolean isCurrentEmpty();
71:
72: /**
73: * Returns an {@link ObjectNode} representing this context.
74: * <p>
75: * The result can thus be added to serialization output.
76: *
77: * @return {@code JsonNode} with registered mappings
78: */
79: ObjectNode getContextNode();
80: }