/
OntologySchema.scala
149 lines (129 loc) · 5.05 KB
/
OntologySchema.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright © 2015-2019 the contributors (see Contributors.md).
*
* This file is part of Knora.
*
* Knora is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Knora is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with Knora. If not, see <http://www.gnu.org/licenses/>.
*/
package org.knora.webapi
/**
* Indicates the schema that a Knora ontology or ontology entity conforms to.
*/
sealed trait OntologySchema
/**
* The schema of Knora ontologies and entities that are used in the triplestore.
*/
case object InternalSchema extends OntologySchema
/**
* The schema of Knora ontologies and entities that are used in API v2.
*/
sealed trait ApiV2Schema extends OntologySchema
/**
* The simple schema for representing Knora ontologies and entities. This schema represents values as literals
* when possible.
*/
case object ApiV2Simple extends ApiV2Schema
/**
* The default (or complex) schema for representing Knora ontologies and entities. This
* schema always represents values as objects.
*/
case object ApiV2Complex extends ApiV2Schema
/**
* A trait representing options that can be submitted to configure an ontology schema.
*/
sealed trait SchemaOption
/**
* A trait representing options that affect the rendering of markup when text values are returned.
*/
sealed trait MarkupRendering extends SchemaOption
/**
* Indicates that markup should be rendered as XML when text values are returned.
*/
case object MarkupAsXml extends MarkupRendering
/**
* Indicates that markup should not be returned with text values, because it will be requested
* separately as standoff.
*/
case object MarkupAsStandoff extends MarkupRendering
/**
* Indicates that no markup should be returned with text values. Used only internally.
*/
case object NoMarkup extends MarkupRendering
/**
* A trait representing options that affect the format of JSON-LD responses.
*/
sealed trait JsonLDRendering extends SchemaOption
/**
* Indicates that flat JSON-LD should be returned, i.e. objects with IRIs should be referenced by IRI
* rather than nested. Blank nodes will still be nested in any case.
*/
case object FlatJsonLD extends JsonLDRendering
/**
* Indicates that hierarchical JSON-LD should be returned, i.e. objects with IRIs should be nested when
* possible, rather than referenced by IRI.
*/
case object HierarchicalJsonLD extends JsonLDRendering
/**
* Utility functions for working with schema options.
*/
object SchemaOptions {
/**
* A set of schema options for querying all standoff markup along with text values.
*/
val ForStandoffWithTextValues: Set[SchemaOption] = Set(MarkupAsXml)
/**
* A set of schema options for querying standoff markup separately from text values.
*/
val ForStandoffSeparateFromTextValues: Set[SchemaOption] = Set(MarkupAsStandoff)
/**
* Determines whether standoff should be queried when a text value is queried.
*
* @param targetSchema the target API schema.
* @param schemaOptions the schema options submitted with the request.
* @return `true` if standoff should be queried.
*/
def queryStandoffWithTextValues(targetSchema: ApiV2Schema, schemaOptions: Set[SchemaOption]): Boolean = {
targetSchema == ApiV2Complex && !schemaOptions.contains(MarkupAsStandoff)
}
/**
* Determines whether markup should be rendered as XML.
*
* @param targetSchema the target API schema.
* @param schemaOptions the schema options submitted with the request.
* @return `true` if markup should be rendered as XML.
*/
def renderMarkupAsXml(targetSchema: ApiV2Schema, schemaOptions: Set[SchemaOption]): Boolean = {
targetSchema == ApiV2Complex && !schemaOptions.contains(MarkupAsStandoff)
}
/**
* Determines whether markup should be rendered as standoff, separately from text values.
*
* @param targetSchema the target API schema.
* @param schemaOptions the schema options submitted with the request.
* @return `true` if markup should be rendered as standoff.
*/
def renderMarkupAsStandoff(targetSchema: ApiV2Schema, schemaOptions: Set[SchemaOption]): Boolean = {
targetSchema == ApiV2Complex && schemaOptions.contains(MarkupAsStandoff)
}
/**
* Determines whether flat JSON-LD should be returned, i.e. objects with IRIs should be referenced by IRI
* rather than nested.
*
* @param schemaOptions the schema options submitted with the request.
* @return `true` if flat JSON-LD should be returned.
*/
def returnFlatJsonLD(schemaOptions: Set[SchemaOption]): Boolean = {
schemaOptions.contains(FlatJsonLD)
}
}