-
Notifications
You must be signed in to change notification settings - Fork 2
/
PersonWithTypedProperties.java
101 lines (85 loc) · 3.43 KB
/
PersonWithTypedProperties.java
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
/**
* Copyright (C) 2022 Czech Technical University in Prague
*
* This program 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 3 of the License, or (at your option) any
* later version.
*
* This program 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/>.
*/
package cz.cvut.kbss.jsonld.environment.model;
import cz.cvut.kbss.jopa.model.annotations.Id;
import cz.cvut.kbss.jopa.model.annotations.OWLClass;
import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty;
import cz.cvut.kbss.jopa.model.annotations.Properties;
import cz.cvut.kbss.jopa.vocabulary.XSD;
import cz.cvut.kbss.jsonld.environment.Vocabulary;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import java.net.URI;
import java.util.Map;
import java.util.Set;
@OWLClass(iri = Vocabulary.EMPLOYEE)
public class PersonWithTypedProperties implements GeneratesRdf {
@Id
public URI uri;
@OWLDataProperty(iri = Vocabulary.FIRST_NAME)
private String firstName;
@OWLDataProperty(iri = Vocabulary.LAST_NAME)
private String lastName;
@Properties
private Map<URI, Set<Object>> properties;
public URI getUri() {
return uri;
}
public void setUri(URI uri) {
this.uri = uri;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Map<URI, Set<Object>> getProperties() {
return properties;
}
public void setProperties(Map<URI, Set<Object>> properties) {
this.properties = properties;
}
@Override
public void toRdf(Model model, ValueFactory vf, Set<URI> visited) {
final IRI id = vf.createIRI(uri.toString());
model.add(id, RDF.TYPE, vf.createIRI(Vocabulary.EMPLOYEE));
model.add(id, vf.createIRI(Vocabulary.FIRST_NAME), vf.createLiteral(firstName));
model.add(id, vf.createIRI(Vocabulary.LAST_NAME), vf.createLiteral(lastName));
if (properties != null) {
properties.forEach((k, v) -> v.forEach(o -> {
if (o instanceof GeneratesRdf) {
final GeneratesRdf entity = (GeneratesRdf) o;
model.add(id, vf.createIRI(k.toString()), vf.createIRI(entity.getUri().toString()));
entity.toRdf(model, vf, visited);
} else if (o instanceof URI) {
model.add(id, vf.createIRI(k.toString()), vf.createIRI(o.toString()));
} else if (o instanceof Integer) {
model.add(id, vf.createIRI(k.toString()), vf.createLiteral(o.toString(), vf.createIRI(XSD.INTEGER)));
} else {
model.add(id, vf.createIRI(k.toString()), vf.createLiteral(o.toString()));
}
}));
}
}
}