-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathStdSubjectMap.java
More file actions
147 lines (129 loc) · 4.86 KB
/
StdSubjectMap.java
File metadata and controls
147 lines (129 loc) · 4.86 KB
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
/*
* Copyright 2011 Antidot opensource@antidot.net
* https://github.com/antidot/db2triples
*
* DB2Triples is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* DB2Triples 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/***************************************************************************
*
* R2RML Model : Standard SubjectMap Class
*
* A subject map is a term map. It specifies a rule
* for generating the subjects of the RDF triples generated
* by a triples map.
*
* modified by mielvandersande
*
****************************************************************************/
package be.ugent.mmlab.rml.model;
import be.ugent.mmlab.rml.model.reference.ReferenceIdentifier;
import java.util.HashSet;
import java.util.Set;
import net.antidot.semantic.rdf.model.tools.RDFDataValidator;
import net.antidot.semantic.rdf.rdb2rdf.r2rml.exception.InvalidR2RMLStructureException;
import net.antidot.semantic.rdf.rdb2rdf.r2rml.exception.InvalidR2RMLSyntaxException;
import net.antidot.semantic.rdf.rdb2rdf.r2rml.exception.R2RMLDataError;
import net.antidot.sql.model.db.ColumnIdentifier;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
public class StdSubjectMap extends AbstractTermMap implements SubjectMap {
private Set<URI> classIRIs;
private HashSet<GraphMap> graphMaps;
protected TriplesMap ownTriplesMap;
public StdSubjectMap(TriplesMap ownTriplesMap, Value constantValue,
String stringTemplate, URI termType, String guard, String inverseExpression,
ReferenceIdentifier referenceValue, Set<URI> classIRIs, Set<GraphMap> graphMaps)
throws R2RMLDataError, InvalidR2RMLStructureException,
InvalidR2RMLSyntaxException {
// No Literal term type
// ==> No datatype
// ==> No specified language tag
super(constantValue, null, null, stringTemplate, termType,guard,
inverseExpression, referenceValue);
setClassIRIs(classIRIs);
setGraphMaps(graphMaps);
setOwnTriplesMap(ownTriplesMap);
}
public void setOwnTriplesMap(TriplesMap ownTriplesMap)
throws InvalidR2RMLStructureException {
// Update triples map if not contains this subject map
if (ownTriplesMap.getSubjectMap() != null)
if (ownTriplesMap.getSubjectMap() != this)
throw new IllegalStateException(
"[StdSubjectMap:setSubjectMap] "
+ "The own triples map "
+ "already contains another Subject Map !");
else
ownTriplesMap.setSubjectMap(this);
this.ownTriplesMap = ownTriplesMap;
}
private void setGraphMaps(Set<GraphMap> graphMaps) {
this.graphMaps = new HashSet<GraphMap>();
if (graphMaps != null)
this.graphMaps.addAll(graphMaps);
}
private void setClassIRIs(Set<URI> classIRIs2) throws R2RMLDataError {
this.classIRIs = new HashSet<URI>();
if (classIRIs2 != null) {
checkClassIRIs(classIRIs);
classIRIs.addAll(classIRIs2);
}
}
private void checkClassIRIs(Set<URI> classIRIs2) throws R2RMLDataError {
// The values of the rr:class property must be IRIs.
for (URI classIRI : classIRIs) {
if (!RDFDataValidator.isValidURI(classIRI.stringValue()))
throw new R2RMLDataError(
"[AbstractTermMap:checkClassIRIs] Not a valid URI : "
+ classIRI);
}
}
public Set<URI> getClassIRIs() {
return classIRIs;
}
protected void checkSpecificTermType(TermType tt)
throws InvalidR2RMLStructureException {
// If the term map is a subject map: rr:IRI or rr:BlankNode
if ((tt != TermType.IRI) && (tt != TermType.BLANK_NODE)) {
throw new InvalidR2RMLStructureException(
"[StdSubjectMap:checkSpecificTermType] If the term map is a "
+ "subject map: only rr:IRI or rr:BlankNode is required");
}
}
protected void checkConstantValue(Value constantValue)
throws R2RMLDataError {
// If the constant-valued term map is a subject map then its constant
// value must be an IRI.
if (!RDFDataValidator.isValidURI(constantValue.stringValue()))
throw new R2RMLDataError(
"[StdSubjectMap:checkConstantValue] Not a valid URI : "
+ constantValue);
}
public Set<GraphMap> getGraphMaps() {
return graphMaps;
}
public TriplesMap getOwnTriplesMap() {
return ownTriplesMap;
}
public String toString() {
String result = super.toString() + " [StdSubjectMap : classIRIs = [";
for (URI uri : classIRIs)
result += uri.getLocalName() + ",";
result += "], graphMaps = [";
for (GraphMap graphMap : graphMaps)
result += graphMap + ",";
result += "]]";
return result;
}
}