Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 25a3030

Browse files
committed
Update ConvertJenaCorese.java
1 parent 3d0256a commit 25a3030

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

corese-jena/src/main/java/fr/inria/corese/jena/convert/ConvertJenaCorese.java

+75-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
import fr.inria.corese.sparql.api.IDatatype;
1919
import fr.inria.corese.sparql.datatype.DatatypeMap;
2020

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+
*/
2131
public class ConvertJenaCorese {
2232

2333
// Factories
@@ -140,16 +150,43 @@ public static Edge quadToEdge(Quad quad) {
140150
return edge;
141151
}
142152

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+
*/
143164
static Edge basicQuadToEdge(Quad quad) {
144165
Node subject_corese = ConvertJenaCorese.JenaNodeToCoreseNode(quad.getSubject());
145166
Node predicate_corese = ConvertJenaCorese.JenaNodeToCoreseNode(quad.getPredicate());
146167
Node object_corese = ConvertJenaCorese.JenaNodeToCoreseNode(quad.getObject());
147168
Node context_corese = ConvertJenaCorese.jenaContextToCoreseContext(quad.getGraph());
148-
169+
149170
return EdgeGeneric.create(context_corese, subject_corese, predicate_corese, object_corese);
150-
}
171+
}
151172

152173
// 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+
*/
153190
public static Edge quadToEdge(Quad quad, int oper, int timestamp) {
154191
int time = timestamp(quad.getGraph());
155192
if (time >= timestamp) {
@@ -193,6 +230,20 @@ public static Iterable<Edge> quadsToEdges(Iterable<Quad> jena_quad_list) {
193230
public static final String RULE_NAME = Entailment.RULE+"_";
194231

195232
// 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+
*/
196247
static org.apache.jena.graph.Node context(Edge edge) {
197248
if (edge.getEdgeIndex()<0) {
198249
return ConvertJenaCorese.coreseContextToJenaContext(edge.getGraph());
@@ -203,13 +254,35 @@ static org.apache.jena.graph.Node context(Edge edge) {
203254
}
204255

205256
// 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+
*/
206267
static void tune(Edge edge) {
207268
if (edge.getGraph().getLabel().startsWith(RULE_NAME)) {
208269
int i = Integer.valueOf(edge.getGraph().getLabel().substring(RULE_NAME.length()));
209270
edge.setEdgeIndex(i);
210271
}
211272
}
212273

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+
*/
213286
static int timestamp(org.apache.jena.graph.Node node) {
214287
if (node.getURI().startsWith(RULE_NAME)) {
215288
int i = Integer.valueOf(node.getURI().substring(RULE_NAME.length()));

0 commit comments

Comments
 (0)