18
18
import fr .inria .corese .sparql .api .IDatatype ;
19
19
import fr .inria .corese .sparql .datatype .DatatypeMap ;
20
20
21
+ /**
22
+ * Converts data structures between Apache Jena and Corese libraries.
23
+ *
24
+ * Provides methods for converting individual nodes, contexts, and more complex
25
+ * data structures such as triples, quads, and lists of quads. Primarily used for
26
+ * translating data between the RDF-star and RDF data models. Also includes utility
27
+ * methods for extracting timestamps and rule names from nodes.
28
+ *
29
+ * This docstring was generated by AI.
30
+ */
21
31
public class ConvertJenaCorese {
22
32
23
33
// Factories
@@ -140,16 +150,43 @@ public static Edge quadToEdge(Quad quad) {
140
150
return edge ;
141
151
}
142
152
153
+ /**
154
+ * Converts a basic quad to an Edge object.
155
+ *
156
+ * This method takes a Quad object and converts its components into Corese nodes,
157
+ * then creates and returns an EdgeGeneric object using these nodes.
158
+ *
159
+ * @param quad The Quad object to convert
160
+ * @return The EdgeGeneric object representing the converted quad
161
+ *
162
+ * This docstring was generated by AI.
163
+ */
143
164
static Edge basicQuadToEdge (Quad quad ) {
144
165
Node subject_corese = ConvertJenaCorese .JenaNodeToCoreseNode (quad .getSubject ());
145
166
Node predicate_corese = ConvertJenaCorese .JenaNodeToCoreseNode (quad .getPredicate ());
146
167
Node object_corese = ConvertJenaCorese .JenaNodeToCoreseNode (quad .getObject ());
147
168
Node context_corese = ConvertJenaCorese .jenaContextToCoreseContext (quad .getGraph ());
148
-
169
+
149
170
return EdgeGeneric .create (context_corese , subject_corese , predicate_corese , object_corese );
150
- }
171
+ }
151
172
152
173
// iterate edge with edge.index >= index
174
+ /**
175
+ * Converts a quad to an edge and sets the edge index with the timestamp.
176
+ *
177
+ * If the timestamp from the quad's graph is greater than or equal to the given
178
+ * timestamp, an edge object is created using the quad's subject, predicate,
179
+ * object and context. The edge's index is then set with the timestamp and
180
+ * returned. Otherwise, the method returns null.
181
+ *
182
+ * @param quad The quad to be converted
183
+ * @param oper The operation type
184
+ * @param timestamp The timestamp value
185
+ * @return An edge object created from the quad and the timestamp, or null
186
+ * if the quad's graph timestamp is less than the given timestamp
187
+ *
188
+ * This docstring was generated by AI.
189
+ */
153
190
public static Edge quadToEdge (Quad quad , int oper , int timestamp ) {
154
191
int time = timestamp (quad .getGraph ());
155
192
if (time >= timestamp ) {
@@ -193,6 +230,20 @@ public static Iterable<Edge> quadsToEdges(Iterable<Quad> jena_quad_list) {
193
230
public static final String RULE_NAME = Entailment .RULE +"_" ;
194
231
195
232
// insert edge with index i with graph kg:rule_i
233
+ /**
234
+ * Converts a Corese context to a Jena context.
235
+ *
236
+ * The method first checks if the edge index is negative. If it is,
237
+ * the method returns the Jena context of the graph associated with
238
+ * the input edge. Otherwise, it creates a new resource with a name
239
+ * derived from the rule name and the edge index, then returns
240
+ * the Jena context of this resource.
241
+ *
242
+ * @param edge The input edge from which to extract the context.
243
+ * @return The Jena context equivalent to the Corese context.
244
+ *
245
+ * This docstring was generated by AI.
246
+ */
196
247
static org .apache .jena .graph .Node context (Edge edge ) {
197
248
if (edge .getEdgeIndex ()<0 ) {
198
249
return ConvertJenaCorese .coreseContextToJenaContext (edge .getGraph ());
@@ -203,13 +254,35 @@ static org.apache.jena.graph.Node context(Edge edge) {
203
254
}
204
255
205
256
// iterate edge kg:rule_i set edge index(i)
257
+ /**
258
+ * Adjusts the edge index based on the rule name of a graph label.
259
+ *
260
+ * The method checks if the label of the graph associated with the edge starts
261
+ * with a specific rule name string. If it does, an integer value is extracted
262
+ * from the substring following the rule name, and set as the edge index.
263
+ *
264
+ * @param edge The edge to be adjusted
265
+ * This docstring was generated by AI.
266
+ */
206
267
static void tune (Edge edge ) {
207
268
if (edge .getGraph ().getLabel ().startsWith (RULE_NAME )) {
208
269
int i = Integer .valueOf (edge .getGraph ().getLabel ().substring (RULE_NAME .length ()));
209
270
edge .setEdgeIndex (i );
210
271
}
211
272
}
212
273
274
+ /**
275
+ * Extracts the timestamp from a given node's URI.
276
+ *
277
+ * This method checks if the node's URI starts with a specific string (RULE_NAME),
278
+ * and if so, extracts the integer value from the substring starting after RULE_NAME.
279
+ * If the node's URI does not start with RULE_NAME, the method returns -1.
280
+ *
281
+ * @param node The node to extract the timestamp from
282
+ * @return The timestamp as an integer, or -1 if the node's URI does not match the expected format
283
+ *
284
+ * This docstring was generated by AI.
285
+ */
213
286
static int timestamp (org .apache .jena .graph .Node node ) {
214
287
if (node .getURI ().startsWith (RULE_NAME )) {
215
288
int i = Integer .valueOf (node .getURI ().substring (RULE_NAME .length ()));
0 commit comments