Skip to content

Package: JsonLdContext

JsonLdContext

nameinstructionbranchcomplexitylinemethod
hasTermMapping(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * JB4JSON-LD
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jsonld.serialization.context;
19:
20: import cz.cvut.kbss.jsonld.serialization.model.JsonNode;
21: import cz.cvut.kbss.jsonld.serialization.model.ObjectNode;
22:
23: import java.util.Optional;
24:
25: /**
26: * Represents the {@literal @context} JSON-LD attribute.
27: */
28: public interface JsonLdContext {
29:
30: /**
31: * Registers the specified term mapping in this context.
32: * <p>
33: * Typically, the {@code term} would be Java attribute (field) name and {@code iri} would be the IRI to which this
34: * field is mapped.
35: *
36: * @param term Mapped term
37: * @param iri IRI to which the term is mapped
38: */
39: void registerTermMapping(String term, String iri);
40:
41: /**
42: * Registers the specified term mapping in this context.
43: * <p>
44: * Compared to {@link #registerTermMapping(String, String)}, this method allows registering more complex mapping
45: * like language containers or typed literals.
46: *
47: * @param term Mapped term
48: * @param mappedNode Node to which the term is mapped
49: */
50: void registerTermMapping(String term, ObjectNode mappedNode);
51:
52: /**
53: * Gets the mapping for the specified term (if it exists).
54: *
55: * @param term Term to get mapping for
56: * @return Optional mapping node
57: */
58: Optional<JsonNode> getTermMapping(String term);
59:
60: /**
61: * Checks whether this JSON-LD context contains mapping for the specified term.
62: *
63: * @param term Term to search mapping for
64: * @return {@code true} if a mapping is already defined for the term, {@code false} otherwise
65: */
66: default boolean hasTermMapping(String term) {
67: return getTermMapping(term).isPresent();
68: }
69:
70: /**
71: * Gets the term mapped to the specified identifier (if it exists).
72: * <p>
73: * This method checks term mapping in this context and finds a term that is mapped to the specified identifier.
74: *
75: * @param iri Identifier the term is mapped to
76: * @return Optional mapped term, empty optional if there is no such term mapping
77: */
78: Optional<String> getMappedTerm(String iri);
79:
80: /**
81: * Checks whether this particular JSON-LD context is empty.
82: * <p>
83: * Term mapping inherited from any parent contexts is not considered.
84: *
85: * @return {@code true} if this context is empty, {@code false} otherwise
86: */
87: boolean isCurrentEmpty();
88:
89: /**
90: * Returns an {@link ObjectNode} representing this context.
91: * <p>
92: * The result can thus be added to serialization output.
93: *
94: * @return {@code JsonNode} with registered mappings
95: */
96: ObjectNode getContextNode();
97: }