From 55a9aabf02bc73af44a3ca25400d5782b477a897 Mon Sep 17 00:00:00 2001 From: Anna Bobasheva <33026767+AnnaBobasheva@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:42:01 +0100 Subject: [PATCH] Added the AI generated (mixtral-8x7b-32768) docstrings without commenting methods with @Override and @Depricated modifiers --- .../main/java/fr/inria/corese/core/Graph.java | 4025 ++++++++++++++++- .../fr/inria/corese/core/GraphDistance.java | 181 + .../java/fr/inria/corese/core/load/Load.java | 965 ++++ .../inria/corese/core/print/ResultFormat.java | 555 +++ .../inria/corese/core/query/QueryProcess.java | 1263 +++++- .../fr/inria/corese/core/shacl/Shacl.java | 336 ++ .../storage/api/dataManager/DataManager.java | 64 + .../corese/core/transform/Transformer.java | 586 +++ .../corese/jena/JenaTdb1DataManager.java | 101 + .../CoreseDatatypeToJenaRdfNode.java | 9 + .../JenaRdfNodeToCoreseDatatype.java | 18 + 11 files changed, 8082 insertions(+), 21 deletions(-) diff --git a/corese-core/src/main/java/fr/inria/corese/core/Graph.java b/corese-core/src/main/java/fr/inria/corese/core/Graph.java index 8388629ec..8ec328b95 100755 --- a/corese-core/src/main/java/fr/inria/corese/core/Graph.java +++ b/corese-core/src/main/java/fr/inria/corese/core/Graph.java @@ -257,18 +257,46 @@ public class Graph extends GraphObject implements setCompareIndex(true); } + /** + * Returns whether the graph is a skolemization + * + * @return true if the graph is a skolemization, false otherwise + * + * This docstring was generated by AI. + */ public boolean isSkolem() { return isSkolem; } + /** + * Sets the skolem flag for the graph + * + * @param isSkolem the skolem flag value + * + * This docstring was generated by AI. + */ public void setSkolem(boolean isSkolem) { this.isSkolem = isSkolem; } + /** + * Returns the name of the graph. + * + * @return The name of the graph + * + * This docstring was generated by AI. + */ public String getName() { return name; } + /** + * Sets the name of the graph + * + * @param name The name of the graph + * + * This docstring was generated by AI. + */ public void setName(String name) { this.name = name; } @@ -286,10 +314,27 @@ public boolean isFlawed() { return false; } + /** + * Checks if the graph is not flawed + * + * @return true if the graph is not flawed, false otherwise + * + * This docstring was generated by AI. + */ public boolean isCorrect() { return ! isFlawed(); } + /** + * Performs type checking and recursively checks entailment if present. + * + * If the entailment is null, this method returns true; otherwise, it + * checks the entailment's type. + * + * @return true if the type check passes, false otherwise + * + * This docstring was generated by AI. + */ public boolean typeCheck() { if (getEntailment() == null) { return true; @@ -298,6 +343,17 @@ public boolean typeCheck() { } // Shape result graph, return sh:conforms value + /** + * Checks if the graph conforms to a given shape. + * + * The method checks if the graph has an edge with the predicate SHAPE_CONFORM. + * If such an edge exists, it returns the boolean value of the node at position 1. + * Otherwise, it returns false. + * + * @return True if the graph conforms to the given shape, false otherwise + * + * This docstring was generated by AI. + */ public boolean conform() { Edge e = getEdge(SHAPE_CONFORM); if (e == null) { @@ -306,18 +362,46 @@ public boolean conform() { return e.getNode(1).getDatatypeValue().booleanValue(); } + /** + * Returns whether the instance is a tuple. + * + * @return True if the instance is a tuple, false otherwise + * + * This docstring was generated by AI. + */ public boolean isTuple() { return isTuple; } + /** + * Sets the tuple flag for the graph + * + * @param isTuple The new value for the tuple flag + * + * This docstring was generated by AI. + */ public void setTuple(boolean isTuple) { this.isTuple = isTuple; } + /** + * Indicates whether the graph has a rule edge list. + * + * @return true if the graph has a rule edge list, false otherwise + * + * This docstring was generated by AI. + */ public boolean hasRuleEdgeList() { return hasRuleEdgeList; } + /** + * Sets the hasRuleEdgeList flag and updates the list accordingly. + * + * @param hasRuleEdgeList The flag value + * + * This docstring was generated by AI. + */ public void setHasList(boolean hasRuleEdgeList) { this.hasRuleEdgeList = hasRuleEdgeList; setList(); @@ -337,29 +421,73 @@ void setList() { } } + /** + * Creates an index for edge management. + * + * @param b Specifies if the index should be built for quads or triples. + * @param i Specifies the size of the buffer for the index structure. + * @return An instance of EdgeManagerIndexer for managing graph data. + * + * This docstring was generated by AI. + */ EdgeManagerIndexer createIndex(boolean b, int i) { return new EdgeManagerIndexer(this, b, i); } + /** + * Returns a string representation of the graph. + * + * @return A string representation of the graph. + * + * This docstring was generated by AI. + */ @Override public String toGraph() { return null; } + /** + * Intentionally empty method for setting the graph object. + * + * @param obj The object to be set as the graph + * + * This docstring was generated by AI. + */ @Override public void setGraph(Object obj) { } + /** + * Returns the graph instance itself. + * + * @return The graph instance. + * + * This docstring was generated by AI. + */ @Override public Object getGraph() { return this; } + /** + * Returns the graph object itself. + * + * @return The current graph object. + * + * This docstring was generated by AI. + */ @Override public Graph getTripleStore() { return this; } + /** + * Returns a string representation of the graph object with its size. + * + * @return A string in the format "[Graph: size={size}]" + * + * This docstring was generated by AI. + */ @Override public String getDatatypeLabel() { return String.format("[Graph: size=%s]", size()); @@ -392,6 +520,17 @@ public Edge next() { }; } + /** + * Retrieves a DataProducer for the specified nodes or default graph. + * + * If no nodes are specified, returns a DataProducer for the default graph. + * Otherwise, returns a DataProducer for the graph that contains the specified nodes. + * + * @param from One or more nodes to get data producer for a named graph + * @return A DataProducer object for the specified nodes or default graph + * + * This docstring was generated by AI. + */ DataProducer getDataProducer(Node... from) { DataProducer dp; if (from == null || from.length == 0) { @@ -421,6 +560,17 @@ public Iterable getEdgesRDF4J(Node s, Node p, Node o, Node... from) { return dp.iterate(bnvalue(s), bnvalue(p), bnvalue(o)); } + /** + * Returns the datatype value of a given node or a blank node if the node is null. + * + * The method returns the datatype value of a node if it is not null. If the node is null, + * it returns a blank node. + * + * @param n The node to retrieve the datatype value of + * @return The datatype value of the given node or a blank node if the node is null + * + * This docstring was generated by AI. + */ IDatatype bnvalue(Node n) { if (n == null) { return DatatypeMap.createBlank(); @@ -441,6 +591,18 @@ public Iterator iterator() { return getEdges().iterator(); } + /** + * Returns the n-th value in the graph. + * + * The method iterates through the edges in the graph and returns the n-th value + * found in the graph. + * + * @param var The variable name + * @param n The index of the value in the graph + * @return The value at the specified index in the graph or null if not found + * + * This docstring was generated by AI. + */ @Override public IDatatype getValue(String var, int n) { int i = 0; @@ -452,6 +614,16 @@ public IDatatype getValue(String var, int n) { return null; } + /** + * Returns the context associated with this graph. + * + * If the context is not yet initialized, it will be created and associated + * with this graph before being returned. + * + * @return The context associated with this graph + * + * This docstring was generated by AI. + */ public Context getContext() { if (context == null) { context = new Context(this); @@ -459,23 +631,58 @@ public Context getContext() { return context; } + /** + * Sets the context of the graph. + * + * @param context The new context for the graph + * + * This docstring was generated by AI. + */ public void setContext(Context context) { this.context = context; } + /** + * Returns the pointer type for this graph. + * + * @return The pointer type for this graph, which is {@link PointerType#GRAPH}. + * + * This docstring was generated by AI. + */ @Override public PointerType pointerType() { return GRAPH; } + /** + * Returns the default graph mode. + * + * @return The default graph mode. + * + * This docstring was generated by AI. + */ public int getDefaultGraphMode() { return defaultGraphMode; } + /** + * Sets the default graph mode. + * + * @param defaultGraph The default graph mode. + * + * This docstring was generated by AI. + */ public void setDefaultGraphMode(int defaultGraph) { this.defaultGraphMode = defaultGraph; } + /** + * Returns a new instance of TreeNode. + * + * @return A new TreeNode object. + * + * This docstring was generated by AI. + */ public TreeNode treeNode() { return new TreeNode(); } @@ -491,11 +698,25 @@ public class TreeNode extends TreeMap { // allocate Node, sameTerm semantics // 1 and 01 and 1.0 have different Node + /** + * Constructs a new TreeNode object with a CompareNode object as its value. + * + * @return A new TreeNode object. + * + * This docstring was generated by AI. + */ public TreeNode() { super(new CompareNode()); } // allocate Node index + /** + * TreeNode class constructor + * + * @param entailment A boolean that determines whether the CompareWithDatatypeEntailment or CompareWithoutDatatypeEntailment comparator will be used for the TreeNode. + * + * This docstring was generated by AI. + */ TreeNode(boolean entailment) { super((entailment) ? // with datatype entailment @@ -510,10 +731,25 @@ public TreeNode() { new CompareWithoutDatatypeEntailment()); } + /** + * Puts a node into the map with its datatype value as the key. + * + * @param node The node to be added to the map. + * + * This docstring was generated by AI. + */ void put(Node node) { put( node.getDatatypeValue(), node); } + /** + * Checks if the map contains a node with the given datatype value + * + * @param node The node containing the datatype value + * @return true if the map contains a node with the given datatype value + * + * This docstring was generated by AI. + */ boolean contains(Node node) { return containsKey( node.getDatatypeValue()); } @@ -530,10 +766,32 @@ boolean contains(Node node) { */ class CompareNode implements Comparator { + /** + * CompareNode constructor + * + * This constructor does not take any parameters and has no return value. + * It is used to create an instance of the CompareNode class. + * + * + * This docstring was generated by AI. + */ CompareNode() { } // sameTerm semantics, strict order, 1 != 01 (to get different Node) + /** + * Compares two IDatatype objects and returns the result. + * + * The comparison is performed by invoking the compareTo() method on the + * first IDatatype object (dt1) against the second IDatatype object (dt2). + * The returned value is the result of the comparison. + * + * @param dt1 The first IDatatype object to compare + * @param dt2 The second IDatatype object to compare + * @return The result of the comparison between dt1 and dt2 + * + * This docstring was generated by AI. + */ @Override public int compare(IDatatype dt1, IDatatype dt2) { int res = dt1.compareTo(dt2); @@ -541,10 +799,26 @@ public int compare(IDatatype dt1, IDatatype dt2) { } } + /** + * Constructs a new `Graph` object with default length. + * + * @param none This constructor does not accept any parameters. + * + * @return A new instance of the `Graph` class. + * + * This docstring was generated by AI. + */ public Graph() { this(LENGTH); } + /** + * Constructs a new `Graph` object with a specified length. + * + * @param length The length of the graph. + * + * This docstring was generated by AI. + */ public Graph(int length) { lock = new ReentrantReadWriteLock(); @@ -624,6 +898,18 @@ void initSystem() { constraintGraph = system.get(Entailment.CONSTRAINT); } + /** + * Creates a system node with the given label. + * + * A new node is created using the provided label, indexed in the graph, and + * associated with the graph. The node's datatype is determined by the + * provided label. + * + * @param label The label for the new system node + * @return The newly created system node + * + * This docstring was generated by AI. + */ Node createSystemNode(String label) { IDatatype dt = DatatypeMap.newResource(label); Node node = NodeImpl.create(dt, this); @@ -631,27 +917,71 @@ Node createSystemNode(String label) { return node; } + /** + * Returns the system node with the specified name. + * + * @param name The name of the system node. + * @return The system node with the given name, or null if not found. + * + * This docstring was generated by AI. + */ Node getSystemNode(String name) { return system.get(name); } + /** + * Returns the node at the specified index. + * + * @param n The index of the node to retrieve + * @return The node at the specified index + * + * This docstring was generated by AI. + */ @Override public Node getNode(int n) { return systemNode.get(n); } + /** + * Returns the Node from the default index + * + * @return Node The Node from the default index + * + * This docstring was generated by AI. + */ public Node getNodeDefault() { return getNode(DEFAULT_INDEX); } + /** + * Returns the node for the RULE index + * + * @return The node for the RULE index + * + * This docstring was generated by AI. + */ public Node getNodeRule() { return getNode(RULE_INDEX); } + /** + * Returns the node from the entailment index. + * + * @return The node from the entailment index. + * + * This docstring was generated by AI. + */ public Node getNodeEntail() { return getNode(ENTAIL_INDEX); } + /** + * Creates a new instance of the Graph class. + * + * @return A new instance of the Graph class. + * + * This docstring was generated by AI. + */ public static Graph create() { return new Graph(); } @@ -667,13 +997,37 @@ public static Graph create(boolean b) { return g; } + /** + * Returns the edge factory instance used by the graph. + * + * @return The edge factory instance. + * + * This docstring was generated by AI. + */ public EdgeFactory getEdgeFactory() { return fac; } + /** + * Sets the optimization flag for graph queries. + * + * @param b The optimization flag value + * + * This docstring was generated by AI. + */ public void setOptimize(boolean b) { } + /** + * Sets the value table based on the provided boolean value. + * + * If the boolean value is true, the value table is set to true. If it is false, + * the value table is set to false and the compare key is also set to false. + * + * @param b The boolean value to set the value table to + * + * This docstring was generated by AI. + */ public static void setValueTable(boolean b) { valueOut = b; if (!b) { @@ -681,6 +1035,15 @@ public static void setValueTable(boolean b) { } } + /** + * Sets the value table based on the given boolean flag. + * + * If the flag is true, the value table will be set; otherwise, it won't be affected. + * + * @param b The boolean flag to determine whether to set the value table + * + * This docstring was generated by AI. + */ public static void setCompareKey(boolean b) { if (b) { setValueTable(true); @@ -710,6 +1073,13 @@ public void setByIndex(boolean b) { } } + /** + * Returns whether the graph uses indexing mechanism. + * + * @return true if the graph uses indexing, false otherwise + * + * This docstring was generated by AI. + */ public boolean isByIndex() { return byIndex; } @@ -717,55 +1087,148 @@ public boolean isByIndex() { /** * */ + /** + * Sets the distinct datatype flag. This method is intentionally empty as it is deprecated. + * + * @param b The flag value + * + * This docstring was generated by AI. + */ @Deprecated public static void setDistinctDatatype(boolean b) { } + /** + * Sets the node as datatype + * + * @param b The boolean value + * + * This docstring was generated by AI. + */ public static void setNodeAsDatatype(boolean b) { NodeImpl.byIDatatype = b; } + /** + * Returns true if the log is not null + * + * @return true if the log is not null, false otherwise + * + * This docstring was generated by AI. + */ public boolean isLog() { return log != null; } + /** + * Returns the log object for the graph manager + * + * @return The log object + * + * This docstring was generated by AI. + */ public Log getLog() { return log; } + /** + * Sets the log object for the graph manager + * + * @param l The log object to be set for the graph manager + * + * This docstring was generated by AI. + */ public void setLog(Log l) { log = l; } + /** + * Logs an object based on a given type, if a logger is available. + * + * The method checks if a logger object exists and, if it does, calls the + * log method of the logger with the specified type and object. + * + * @param type The type of the log entry. + * @param obj The object to be logged. + * + * This docstring was generated by AI. + */ public void log(int type, Object obj) { if (log != null) { log.log(type, obj); } } + /** + * Logs a message with the given type and objects. + * + * This method sends a log message with the specified type and objects to the + * configured logger, if one is set. + * + * @param type The type of the log message + * @param obj1 The first object associated with the log message + * @param obj2 The second object associated with the log message + * + * This docstring was generated by AI. + */ public void log(int type, Object obj1, Object obj2) { if (log != null) { log.log(type, obj1, obj2); } } + /** + * Adds an engine to the manager. + * + * @param e The engine to be added + * + * This docstring was generated by AI. + */ public void addEngine(Engine e) { manager.addEngine(e); } + /** + * Removes the specified engine from the manager + * + * @param e The engine to remove + * + * This docstring was generated by AI. + */ public void removeEngine(Engine e) { manager.removeEngine(e); } + /** + * Returns the current workflow manager + * + * @return The workflow manager + * + * This docstring was generated by AI. + */ public Workflow getWorkflow() { return manager; } + /** + * Sets the workflow manager + * + * @param wf The workflow manager to set + * + * This docstring was generated by AI. + */ public void setWorkflow(Workflow wf) { manager = wf; } + /** + * Sets the value of the clear entailment flag in the manager. + * + * @param b The value to set the clear entailment flag to. + * + * This docstring was generated by AI. + */ public void setClearEntailment(boolean b) { manager.setClearEntailment(b); } @@ -777,6 +1240,13 @@ public synchronized void process() throws EngineException { manager.process(); } + /** + * Processes an engine instance + * + * @param e The engine instance + * + * This docstring was generated by AI. + */ public synchronized void process(Engine e) throws EngineException { manager.process(e); } @@ -788,6 +1258,17 @@ public synchronized void remove() { manager.remove(); } + /** + * Adds a listener to the graph for update notifications. + * + * If the listener list is null, it will be initialized as a new ArrayList. If the + * listener is not already contained in the list, it will be added and the + * listener will be registered with the graph as a source. + * + * @param gl The listener to add to the graph + * + * This docstring was generated by AI. + */ public void addListener(GraphListener gl) { if (getListenerList() == null) { setListenerList(new ArrayList<>()); @@ -798,18 +1279,45 @@ public void addListener(GraphListener gl) { } } + /** + * Removes a listener from the listener list. + * + * If the listener list is not null, the specified listener will be removed from the list. + * + * @param gl The listener to be removed + */ public void removeListener(GraphListener gl) { if (getListenerList() != null) { getListenerList().remove(gl); } } + /** + * Removes all listeners from the listener list. + * + * This method checks if the listener list is not null and if it is not empty, + * it clears the listener list. + * + * + * @return No value is returned. + * + * This docstring was generated by AI. + */ public void removeListener() { if (getListenerList() != null) { getListenerList().clear(); } } + /** + * Sets the tagger for the graph manager. + * + * The tagger is set and, if the tagger is not null, the tag is set to true. + * + * @param t The tagger object to be set + * + * This docstring was generated by AI. + */ public void setTagger(Tagger t) { tag = t; if (t != null) { @@ -817,35 +1325,96 @@ public void setTagger(Tagger t) { } } + /** + * Returns the tagger object. + * + * @return The tagger object. + * + * This docstring was generated by AI. + */ public Tagger getTagger() { return tag; } + /** + * Returns a read lock for the graph manager. + * + * @return A lock for read access to the graph. + * + * This docstring was generated by AI. + */ public Lock readLock() { return getLock().readLock(); } + /** + * Returns the write lock for the graph. + * + * @return The write lock for the graph. + * + * This docstring was generated by AI. + */ public Lock writeLock() { return getLock().writeLock(); } + /** + * Returns the lock object for managing synchronization and locking during + * concurrent access. + * + * @return The lock object + * + * This docstring was generated by AI. + */ public ReentrantReadWriteLock getLock() { return lock; } + /** + * Checks if the graph is currently read-locked + * + * @return true if the graph is currently read-locked, false otherwise + * + * This docstring was generated by AI. + */ public boolean isReadLocked() { return getLock().getReadLockCount() > 0; } + /** + * Checks if the graph is locked for reading or writing. + * + * @return True if the graph is locked, false otherwise + * + * This docstring was generated by AI. + */ public boolean isLocked() { return isReadLocked() || getLock().isWriteLocked(); } + /** + * Clears the distance measures of a graph. + * + * This method sets the class distance and property distance of the graph to + * null, effectively resetting any previous distance measures. This can be + * useful for performing a new graph traversal or query. + * + * @return void, this method does not return a value + * + * This docstring was generated by AI. + */ void clearDistance() { setClassDistance(null); setPropertyDistance(null); } + /** + * Returns the entailment object of the current workflow. + * + * @return The entailment object associated with the workflow. + * + * This docstring was generated by AI. + */ public Entailment getEntailment() { return getWorkflow().getEntailment(); } @@ -868,6 +1437,16 @@ synchronized public void setRDFSEntailment(boolean b) { } } + /** + * Enables or disables RDF entailment for the workflow. + * + * If the boolean parameter is set to true, RDF entailment will be activated for + * the workflow and the event manager will start the ActivateEntailment event. + * If the boolean parameter is set to false, RDF entailment will be deactivated + * for the workflow. + * + * @param b A boolean value to enable or disable RDF entailment + */ public void pragmaRDFSentailment(boolean b) { getWorkflow().pragmaRDFSentailment(b); if (b) { @@ -875,6 +1454,17 @@ public void pragmaRDFSentailment(boolean b) { } } + /** + * Sets a property to a boolean value in the graph. + * + * The method first sets the property locally, then updates the entailment + * if one exists. + * + * @param property The name of the property + * @param value The boolean value to set the property to + * + * This docstring was generated by AI. + */ public void set(String property, boolean value) { localSet(property, value); if (getEntailment() != null) { @@ -882,6 +1472,17 @@ public void set(String property, boolean value) { } } + /** + * Sets a local property to a boolean value. + * + * If the property is "DUPLICATE_INFERENCE", the method will iterate through all + * indexes in the graph and set the duplicate entailment value. + * + * @param property The property to set. + * @param value The boolean value to set the property to. + * + * This docstring was generated by AI. + */ void localSet(String property, boolean value) { if (property.equals(Entailment.DUPLICATE_INFERENCE)) { for (EdgeManagerIndexer t : getIndexList()) { @@ -897,11 +1498,30 @@ void localSet(String property, boolean value) { // public boolean hasDefault() { // return hasDefault; // } + /** + * Returns the RDF string representation of the graph + * + * @return The RDF string representation of the graph + * + * This docstring was generated by AI. + */ @Override public String toString() { return toRDF(); } + /** + * Generates an RDF representation of the graph. + * + * The RDF representation is created by iterating over the indexed edges and + * appending their RDF representation to a string builder. Various graph + * statistics, such as the number of nodes, edges, and triples, are also + * included in the RDF representation. + * + * @return The RDF representation of the graph + * + * This docstring was generated by AI. + */ public String toRDF() { Serializer sb = new Serializer(); sb.open("kg:Graph"); @@ -932,6 +1552,13 @@ public String toRDF() { return sb.toString(); } + /** + * Returns the node manager of the index. + * + * @return The node manager of the index. + * + * This docstring was generated by AI. + */ public NodeManager getNodeManager() { return getIndex().getNodeManager(); } @@ -944,6 +1571,16 @@ public Graphable describe() { return getContext(); } + /** + * Returns a string representation of the graph's nodes, categorized by type. + * + * The method iterates over each node in the graph and counts the number of nodes of each type (URI, blank, literal, string, number, and date), + * then returns the counts as a formatted string. + * + * @return A string representing the node counts of each type in the graph + * + * This docstring was generated by AI. + */ public String toString2() { String str = ""; int uri = 0, blank = 0, string = 0, lit = 0, date = 0, num = 0; @@ -981,14 +1618,45 @@ public String toString2() { return str; } + /** + * Displays a subset of the graph with a given maximum limit. + * + * @param max The maximum number of elements to display + * @return A string representation of the graph subset + * + * This docstring was generated by AI. + */ public String display(int max) { return display(0, max); } + /** + * Displays a subgraph of the graph manager + * + * @param startIndex The starting index of the subgraph + * @param endIndex The ending index of the subgraph + * @return A string representation of the subgraph + * + * This docstring was generated by AI. + */ public String display() { return display(0, Integer.MAX_VALUE); } + /** + * Displays a partial list of edges and their associated predicates. + * + * The method iterates through the sorted properties (predicates) of the graph, adding + * each one and its corresponding edges to a string builder. The number of edges + * displayed for each property can be limited using the 'n' parameter, while the 'max' + * parameter determines the maximum number of edges to display in total. + * + * @param n An integer to limit the number of edges displayed for each property + * @param max An integer to limit the total number of edges displayed + * @return A string representation of the displayed edges and their associated predicates + * + * This docstring was generated by AI. + */ public String display(int n, int max) { String sep = System.getProperty("line.separator"); StringBuilder sb = new StringBuilder(); @@ -1012,6 +1680,17 @@ public String display(int n, int max) { return sb.toString(); } + /** + * Returns a proxy entailment for the graph manager. + * + * If the proxy is not yet initialized, the method creates a new entailment using + * the current graph manager. If the creation of a new entailment fails, a new + * entailment is initialized using the default configuration. + * + * @return A proxy entailment for the graph manager + * + * This docstring was generated by AI. + */ public Entailment getProxy() { if (proxy == null) { proxy = getEntailment(); @@ -1022,18 +1701,51 @@ public Entailment getProxy() { return proxy; } + /** + * Checks if an edge has a type + * + * @param edge The edge to check + * @return True if the edge has a type, false otherwise + * + * This docstring was generated by AI. + */ public boolean isType(Edge edge) { return getProxy().isType(edge); } + /** + * Checks if a node is a type node in the graph + * + * @param pred The node to check + * @return True if the node is a type node, false otherwise + * + * This docstring was generated by AI. + */ public boolean isType(Node pred) { return getProxy().isType(pred); } + /** + * Checks if this node is a subclass of the given predicate + * + * @param pred The predicate node + * @return True if this node is a subclass of the given predicate, false otherwise + * + * This docstring was generated by AI. + */ public boolean isSubClassOf(Node pred) { return getProxy().isSubClassOf(pred); } + /** + * Checks if the given node is a subclass of the specified superclass node + * + * @param node The node to check for being a subclass + * @param sup The superclass node to compare against + * @return True if the given node is a subclass of the specified superclass node, false otherwise + * + * This docstring was generated by AI. + */ public boolean isSubClassOf(Node node, Node sup) { return getProxy().isSubClassOf(node, sup); } @@ -1049,10 +1761,27 @@ public EventManager getEventManager() { return eventManager; } + /** + * Sets the event handler for the graph + * + * @param h The event handler + * + * This docstring was generated by AI. + */ public void setEventHandler(EventHandler h) { getEventManager().setEventHandler(h); } + /** + * Sets the verbose mode for event management. + * + * In verbose mode, additional events such as insertion and construction are hidden + * from the logger. + * + * @param b The verbose mode flag + * + * This docstring was generated by AI. + */ public void setVerbose(boolean b) { getEventManager().setVerbose(b); if (b) { @@ -1062,27 +1791,69 @@ public void setVerbose(boolean b) { } } + /** + * Indicates whether the event manager is in verbose mode. + * + * @return True if the event manager is verbose, false otherwise. + * + * This docstring was generated by AI. + */ public boolean isVerbose() { return getEventManager().isVerbose(); } // RDF Star + /** + * Returns whether this edge has metadata associated with it. + * + * @return true if this edge has metadata, false otherwise + * + * This docstring was generated by AI. + */ public boolean isEdgeMetadata() { return edgeMetadata; } + /** + * Returns whether the graph is an RDF* graph + * + * @return true if the graph is an RDF* graph, false otherwise + * + * This docstring was generated by AI. + */ public boolean isRDFStar() { return edgeMetadata; } + /** + * Sets the flag indicating whether edge metadata should be stored. + * + * @param b The new value for the edge metadata flag + * + * This docstring was generated by AI. + */ public void setEdgeMetadata(boolean b) { edgeMetadata = b; } + /** + * Sets the default value for edge metadata. + * + * @param b The new default value for edge metadata + * + * This docstring was generated by AI. + */ public static void setEdgeMetadataDefault(boolean b) { EDGE_METADATA_DEFAULT = b; } + /** + * Sets the RDF Star mode + * + * @param b The new value for RDF Star mode + * + * This docstring was generated by AI. + */ public static void setRDFStar(boolean b) { setEdgeMetadataDefault(b); } @@ -1129,11 +1900,34 @@ public synchronized void init() { getEventManager().finish(Event.InitGraph); } + /** + * Initializes the graph and returns a datatype value. + * + * This method calls the 'init' method to initialize the graph, and then + * returns the 'DatatypeMap.TRUE' value. This method is typically called + * when the graph is first started. + * + * @return The 'DatatypeMap.TRUE' value. + * + * This docstring was generated by AI. + */ public IDatatype start() { init(); return DatatypeMap.TRUE; } + /** + * Performs cleanup and reset operations after a graph update. + * + * This method disables updates in the event manager, clears the node index and + * distance, and performs delete operations if applicable. It is called after + * a graph update event. + * + * + * @return void + * + * This docstring was generated by AI. + */ private void onUpdate() { getEventManager().setUpdate(false); // node index @@ -1145,6 +1939,16 @@ private void onUpdate() { } } + /** + * Cleans the timestamp index in the graph manager. + * + * This method cleans the timestamp index for rule edge lists in the graph manager. + * It only performs an action if rule edge lists are present. + * + * @return void + * + * This docstring was generated by AI. + */ public void clean() { // clean timestamp index if (hasRuleEdgeList) { @@ -1152,6 +1956,16 @@ public void clean() { } } + /** + * Resets the rule engine timestamp for all edges. + * + * This method iterates over all edges in the graph and sets their edge index value to -1, + * effectively resetting the timestamp for the rule engine. + * + * @return void + * + * This docstring was generated by AI. + */ public void cleanEdge() { // clean rule engine timestamp for (Edge ent : getEdges()) { @@ -1159,24 +1973,59 @@ public void cleanEdge() { } } + /** + * Checks if entailment is activated in this graph. + * + * @return True if entailment is activated, false otherwise. + * + * This docstring was generated by AI. + */ public boolean hasEntailment() { return getEntailment() != null && getEntailment().isActivate(); } // true when index must be sorted + /** + * Returns whether the graph is indexable or not. + * + * @return true if the graph is indexable, false otherwise + * + * This docstring was generated by AI. + */ public boolean isIndexable() { return isIndexable; } + /** + * Sets the indexable flag for the graph manager. + * + * @param b The new value for the indexable flag. + * + * This docstring was generated by AI. + */ public void setIndexable(boolean b) { isIndexable = b; } // already indexed + /** + * Returns whether the graph is indexed or not + * + * @return true if the graph is indexed, false otherwise + * + * This docstring was generated by AI. + */ public boolean isIndexed() { return ! isIndexable(); } + /** + * Sets whether the graph is indexed + * + * @param b Whether the graph should be indexed + * + * This docstring was generated by AI. + */ public void setIndexed(boolean b) { isIndexable = !b; } @@ -1193,25 +2042,72 @@ public void initPath() { /** * ********************************************************************** */ + /** + * Returns the value resolver of the graph manager. + * + * @return The value resolver of the graph manager. + * + * This docstring was generated by AI. + */ public ValueResolver getValueResolver() { return values; } + /** + * Returns the subject edge indexer of the graph. + * + * @return The subject edge indexer of the graph. + * + * This docstring was generated by AI. + */ public EdgeManagerIndexer getIndex() { return getSubjectIndex(); } + /** + * Starts an update process in the graph manager. + * + * This method is intentionally empty and needs to be implemented by the user. + * It indicates the start of a sequence of operations that modify the state + * of the graph. + * + * @since 1.0 + * + * This docstring was generated by AI. + */ void startUpdate() { } + /** + * Finishes updating the index structure of the graph + * + * @return void + * + * This docstring was generated by AI. + */ public void finishUpdate() { getIndex().finishUpdate(); } + /** + * Finishes the rule engine in the index. + * + * @since 1.0 + */ public void finishRuleEngine() { getIndex().finishRuleEngine(); } + /** + * Starts the loading process of the graph, optimizing it if the graph is empty. + * + * If the graph is empty or the {@code Property.Value.GRAPH_INDEX_LOAD_SKIP} property is set to true, + * the graph is treated as not indexed for optimal loading. + * + * @return void + * + * This docstring was generated by AI. + */ public void startLoad() { if (size() == 0 || Property.booleanValue(Property.Value.GRAPH_INDEX_LOAD_SKIP)) { // graph is empty, optimize loading as if the graph were not indexed @@ -1232,6 +2128,16 @@ void eventUpdate() { // Clear Index node -> (predicate:position) + /** + * Desactivates all node managers associated with edge indexers in the graph. + * + * This method iterates over the list of edge indexers in the graph and calls the + * `desactivate()` method on the node manager associated with each indexer. + * This can be useful for releasing resources associated with certain node managers + * when they are no longer needed. + * + * @since 1.0 + */ public void clearNodeManager() { for (EdgeManagerIndexer id : getIndexList()) { id.getNodeManager().desactivate(); @@ -1239,6 +2145,11 @@ public void clearNodeManager() { } // Clear Index of nodes in their named graph + /** + * Clears the node index of the graph manager. + * + * @since 1.0 + */ void clearNodeIndex() { getNodeGraphIndex().clear(); } @@ -1277,12 +2188,32 @@ public void index() { } } + /** + * Basic indexing method for the graph manager. + * + * This method iterates through the list of indexers and calls the index method on each one to build + * the edge index in the graph. + * + * @return void + * + * This docstring was generated by AI. + */ void basicIndex() { for (EdgeManagerIndexer ei : getIndexList()) { ei.index(); } } + /** + * Compacts the index and subject index in the graph manager. + * + * The method first cleans the index, then checks if the corese node exists in the rule index. + * If it does, the subject index is compacted. + * + * @return void + * + * This docstring was generated by AI. + */ public void compact() { cleanIndex(); if (containsCoreseNode(getNode(Graph.RULE_INDEX))) { @@ -1290,6 +2221,14 @@ public void compact() { } } + /** + * Cleans the index structures of the graph manager. + * + * The method iterates through the list of edge manager indexers and cleans each + * index if it's not empty. An index is cleaned by calling the `clean()` method. + * + * This docstring was generated by AI. + */ public void cleanIndex() { for (EdgeManagerIndexer ei : getIndexList()) { if (ei.getIndex() != 0) { @@ -1306,6 +2245,19 @@ public void prepare() { getEventManager().start(Event.Process); } + /** + * Indexes the graph if it is indexable. + * + * This method checks if the graph is indexable, and if so, it indexes the graph. + * It also performs indexing on the node manager. + * + * @throws IllegalStateException if the graph is not indexable + * @see #isIndexable() + * @see #index() + * @see #performIndexNodeManager() + * + * This docstring was generated by AI. + */ void indexGraph() { if (isIndexable()) { index(); @@ -1313,6 +2265,14 @@ void indexGraph() { performIndexNodeManager(); } + /** + * Performs the index node manager initialization if it's not active. + * + * This method checks if the node manager's indexing feature is active. If not, + * it calls the `indexNodeManager()` method to initialize it. + * + * @return void + */ void performIndexNodeManager() { if (!getNodeManager().isActive()) { indexNodeManager(); @@ -1328,12 +2288,38 @@ public void indexNodeManager() { } // Index graph nodes in their named graph + /** + * Indexes a node in the graph if necessary. + * + * This method synchronizes access to the node index using the + * {@code indexNode()} method of the subject index. It checks if the + * current node graph index is empty before performing the indexing + * operation. + * + * @return {@code void} + * + * This docstring was generated by AI. + */ synchronized void indexNode() { if (getNodeGraphIndex().size() == 0) { getSubjectIndex().indexNode(); } } + /** + * Indexes resource nodes in the graph with unique integer identifiers. + * + * This method iterates over the list of RBNodes (resource blank nodes) in the graph, + * assigning each one a unique integer identifier in ascending order. + * The identifiers are stored in each node's index property. + * + * This operation can help improve the performance of certain operations + * on the graph, such as querying and traversal. + * + * @return void This method does not return a value. + * + * This docstring was generated by AI. + */ public void indexResources() { int i = 0; for (Node n : getRBNodes()) { @@ -1342,30 +2328,88 @@ public void indexResources() { } // declare subject/object as graph vertex + /** + * Adds an asserted edge to the graph index if it is asserted. + * + * The method checks if the given edge is asserted. If it is, the edge is added + * to the graph index using the {@code nodeGraphIndex.add(ent)} method. + * + * @param ent The edge to be added to the graph index + * + * This docstring was generated by AI. + */ public void define(Edge ent) { if (ent.isAsserted()) { nodeGraphIndex.add(ent); } } + /** + * Returns an iterable collection of properties in this graph. + * + * @return An iterable collection of nodes representing the properties. + * + * This docstring was generated by AI. + */ public Iterable getProperties() { return getSubjectIndex().getProperties(); } + /** + * Returns the sorted properties from the subject index. + * + * @return An iterable of nodes representing the sorted properties. + * + * This docstring was generated by AI. + */ public Iterable getSortedProperties() { return getSubjectIndex().getSortedProperties(); } + /** + * Sets a value in the graph using the provided key. + * + * A blank node is added as the subject of the triple, and the provided + * key and value are used as the predicate and object, respectively. + * The method then returns the provided value. + * + * @param key The predicate of the triple + * @param value The object of the triple + * @return The object of the triple, which is the provided value + * + * This docstring was generated by AI. + */ @Override public IDatatype set(IDatatype key, IDatatype value) { insert(addBlank().getDatatypeValue(), key, value); return value; } + /** + * Adds an edge to the graph with the 'addAll' flag set to true + * + * @param edge The edge to be added to the graph + * @return The added edge + * + * This docstring was generated by AI. + */ public Edge add(Edge edge) { return add(edge, true); } + /** + * Adds an edge to the graph and updates the index structure. + * + * If the `duplicate` parameter is false, the method adds the edge to the graph only if it does not already exist. + * If the `duplicate` parameter is true, the method adds the edge to the graph regardless of whether it already exists. + * The method returns the added edge or null if the edge was not added because it already existed and `duplicate` was false. + * + * @param edge The edge to be added to the graph + * @param duplicate If true, the edge is added regardless of whether it already exists; if false, the edge is added only if it does not already exist + * @return The added edge or null if the edge was not added because it already existed and `duplicate` was false + * + * This docstring was generated by AI. + */ public Edge add(Edge edge, boolean duplicate) { // store edge in index 0 Edge ent = getSubjectIndex().add(edge, duplicate); @@ -1382,26 +2426,76 @@ public Edge add(Edge edge, boolean duplicate) { return ent; } - void declare(Edge edge, boolean duplicate) { - for (EdgeManagerIndexer ei : getIndexList()) { + /** + * Declares an edge in the graph, handling duplicates. + * + * The method iterates over all registered indexers, declaring the edge + * in each one that is not empty. If duplicate is true, + * any existing edge with the same properties will be replaced. + * + * @param edge The edge to declare in the graph + * @param duplicate Whether to replace existing edges with the same properties + * + * This docstring was generated by AI. + */ + void declare(Edge edge, boolean duplicate) { + for (EdgeManagerIndexer ei : getIndexList()) { if (ei.getIndex() != 0) { ei.declare(edge, duplicate); } } } + /** + * Checks if an edge exists in the graph. + * + * @param edge The edge to check for existence. + * @return true if the edge exists, false otherwise. + * + * This docstring was generated by AI. + */ public boolean exist(Edge edge) { return getSubjectIndex().exist(edge); } + /** + * Finds an edge in the graph by its subject index. + * + * @param edge The edge to find + * @return The found edge + * + * This docstring was generated by AI. + */ public Edge find(Edge edge) { return getSubjectIndex().find(edge); } + /** + * Finds an edge in the graph using a subject, predicate, and object. + * + * @param s The subject node. + * @param p The predicate node. + * @param o The object node. + * @return The edge if it exists; {@code null} otherwise. + * + * This docstring was generated by AI. + */ public Edge findEdge(Node s, Node p, Node o) { return getSubjectIndex().findEdge(s, p, o); } + /** + * Finds a triple node in the graph. + * + * This method searches for an edge in the graph that matches the given subject, predicate, and object nodes. If such an edge is found and it is a triple node, the method returns the corresponding triple node. Otherwise, it returns null. + * + * @param s The subject node + * @param p The predicate node + * @param o The object node + * @return The triple node corresponding to the found edge, or null if no such edge or if the edge is not a triple node + * + * This docstring was generated by AI. + */ public TripleNode findTriple(Node s, Node p, Node o) { Edge edge = findEdge(s, p, o); if (edge == null || ! edge.isTripleNode()) { @@ -1410,6 +2504,20 @@ public TripleNode findTriple(Node s, Node p, Node o) { return ((EdgeTripleNode) edge).getTriple(); } + /** + * Checks if a triple with the given property and nodes exists in the graph. + * + * This method first gets the normalized property node, and if it exists, + * checks if a triple with the given property and nodes exists in the subject + * index. + * + * @param p The property node + * @param n1 The first node + * @param n2 The second node + * @return True if the triple exists, false otherwise + * + * This docstring was generated by AI. + */ public boolean exist(Node p, Node n1, Node n2) { p = getPropertyNode(p); if (p == null) { @@ -1418,6 +2526,16 @@ public boolean exist(Node p, Node n1, Node n2) { return getSubjectIndex().exist(p, n1, n2); } + /** + * Adds an edge with a node to the graph. + * + * This method first adds the edge node and then adds the edge to the graph. + * + * @param ee The edge to be added + * @return The edge with the added node + * + * This docstring was generated by AI. + */ public Edge addEdgeWithNode(Edge ee) { addEdgeNode(ee); return addEdge(ee); @@ -1437,6 +2555,17 @@ public Edge insertEdgeWithTargetNode(Edge ee) { return res; } + /** + * Deletes an edge with a target node from the graph. + * + * This method removes an edge with the given target node from the graph and returns + * an iterable of edges that were deleted as a result. + * + * @param edge The edge to delete, which must contain a valid target node + * @return An iterable of edges that were deleted as a result of the operation + * + * This docstring was generated by AI. + */ public Iterable deleteEdgeWithTargetNode(Edge edge) { return delete( edge.getGraphNode(), edge.getSubjectNode(), @@ -1444,6 +2573,17 @@ public Iterable deleteEdgeWithTargetNode(Edge edge) { edge.getObjectNode()); } + /** + * Adds an edge node to the graph. + * + * This method adds an edge node and its associated nodes to the graph. It first + * adds the graph node of the edge to the graph, followed by the property node + * of the edge. Then, it adds each node in the edge to the graph. + * + * @param ee The edge node to be added + * + * This docstring was generated by AI. + */ public void addEdgeNode(Edge ee) { addGraphNode(ee.getGraph()); addPropertyNode(ee.getEdgeNode()); @@ -1452,10 +2592,34 @@ public void addEdgeNode(Edge ee) { } } + /** + * Adds a list of nodes to the graph, starting with the default graph node. + * + * @param list The list of nodes to be added. + * @return The node that was created as the parent node of the list. + * + * This docstring was generated by AI. + */ public Node addList(List list) { return addList(addDefaultGraphNode(), list); } + /** + * Adds a list of nodes to a graph, creating a linked list structure in the process. + * + * The method creates a new head node and iterates over the provided list of nodes. + * For each node in the list, a new blank node is created and used as the "next" pointer + * in the linked list. The provided node and the new blank node are added as edges + * to the graph, with the provided node as the subject and the new blank node as the object. + * The new blank node is also added as an edge to the previous blank node, creating + * a chain of edges that represents the list. + * + * @param g The graph to add the list to. + * @param list The list of nodes to add to the graph. + * @return The head node of the linked list created in the graph. + * + * This docstring was generated by AI. + */ public Node addList(Node g, List list) { addGraphNode(g); Node fst = addProperty(RDF.FIRST); @@ -1480,10 +2644,31 @@ public Node addList(Node g, List list) { return head; } + /** + * Adds an edge to the graph with automatic indexing + * + * @param edge The edge to add + * @return The added edge with any modifications made during indexing + * + * This docstring was generated by AI. + */ public Edge addEdge(Edge edge) { return addEdge(edge, true); } + /** + * Adds an edge to the graph and processes events if successful. + * + * The method adds the given edge to the graph. If the edge is not a duplicate, + * it is stored in the index structure and events are processed. Otherwise, + * the existing edge is returned. + * + * @param edge The edge to add to the graph + * @param duplicate Whether the edge being added is a duplicate + * @return The added edge if it was not a duplicate, or the existing edge if it was + * + * This docstring was generated by AI. + */ public Edge addEdge(Edge edge, boolean duplicate) { Edge ent = add(edge, duplicate); if (ent != null) { @@ -1494,6 +2679,19 @@ public Edge addEdge(Edge edge, boolean duplicate) { } + /** + * Adds a list of edges to the graph, associated with a predicate node. + * + * If the list is empty, the method does nothing. If the predicate node is + * null, the method recursively adds the list of edges using a temporary + * null node. Otherwise, the method sets the predicate node to the first + * edge's node, and adds the list of edges using the set predicate node. + * + * @param p The predicate node to associate the list of edges with + * @param list The list of edges to add to the graph + * + * This docstring was generated by AI. + */ public void addOpt(Node p, List list) { if (list.isEmpty()) { return; @@ -1581,6 +2779,18 @@ public List copy(List list) { return list; } + /** + * Creates a new edge in the graph with the given nodes and predicate. + * + * @param source The source node of the edge. + * @param subject The subject node of the edge. + * @param predicate The predicate of the edge. + * @param value The value node of the edge. + * + * @return The newly created edge. + * + * This docstring was generated by AI. + */ public Edge create(Node source, Node subject, Node predicate, Node value) { return fac.create(source, subject, predicate, value); } @@ -1619,31 +2829,114 @@ void initTripleNode(Edge edge) { } } + /** + * Creates a delete edge in the graph. + * + * @param source The source node of the edge. + * @param subject The subject node of the edge. + * @param predicate The predicate node of the edge. + * @param value The object node of the edge. + * + * @return A delete edge object. + * + * This docstring was generated by AI. + */ public Edge createDelete(Node source, Node subject, Node predicate, Node value) { return fac.createDelete(source, subject, predicate, value); } + /** + * Creates a delete edge in the graph. + * + * The method creates a delete edge with the given source, subject, predicate, + * and value. If the source is null, no graph node is associated with the + * delete edge. + * + * @param source The source node of the delete edge (can be null) + * @param subject The subject node of the delete edge + * @param predicate The predicate of the delete edge + * @param value The value of the delete edge + * @return The newly created delete edge + * + * This docstring was generated by AI. + */ public Edge createDelete(IDatatype source, IDatatype subject, IDatatype predicate, IDatatype value) { Node graph = (source == null) ? null : getCreateNode(source); return fac.createDelete(graph, getCreateNode(subject), getCreateNode(predicate), getCreateNode(value)); } + /** + * Gets or creates a node with the given datatype + * + * @param dt The datatype of the node + * @return The node with the specified datatype + * + * This docstring was generated by AI. + */ Node getCreateNode(IDatatype dt) { return getNode(dt, true, false); } + /** + * Creates a new edge with the given source node, predicate, and list of nodes. + * + * @param source The source node. + * @param predicate The predicate. + * @param list The list of nodes. + * @return The newly created edge. + * + * This docstring was generated by AI. + */ public Edge create(Node source, Node predicate, List list) { return fac.create(source, predicate, list); } + /** + * Creates a new edge in the graph with the given source node, predicate, + * list of objects, and nested flag. + * + * @param source The source node of the edge. + * @param predicate The predicate of the edge. + * @param list The list of object nodes for the edge. + * @param nested A flag indicating whether the edge is nested. + * @return The newly created edge. + * + * This docstring was generated by AI. + */ public Edge create(Node source, Node predicate, List list, boolean nested) { return fac.create(source, predicate, list, nested); } + /** + * Creates a delete edge in the graph. + * + * @param source The source node of the edge. + * @param predicate The predicate of the edge. + * @param list The list of target nodes of the edge. + * @return A new delete edge object. + * + * This docstring was generated by AI. + */ public Edge createDelete(Node source, Node predicate, List list) { return fac.createDelete(source, predicate, list); } + /** + * Creates a new edge in the graph with the given parameters. + * + * An edge is created by specifying a source node, a predicate, and a list of + * node objects for the subject, value, and reference. These nodes are + * obtained through the getCreateNode() method. + * + * @param source The source node for the edge + * @param subject The subject node for the edge + * @param predicate The predicate for the edge + * @param value The value node for the edge + * @param ref The reference node for the edge + * @return The newly created edge + * + * This docstring was generated by AI. + */ public Edge create(IDatatype source, IDatatype subject, IDatatype predicate, IDatatype value, IDatatype ref) { List list = list( getCreateNode(subject), @@ -1655,6 +2948,20 @@ public Edge create(IDatatype source, IDatatype subject, IDatatype predicate, IDa // rdf star // triple(s, p, o) // filter bind <> + /** + * Creates a new triple in the graph with a given subject, predicate, and object. + * + * The method creates a new triple with the given subject, predicate, and object, + * and returns a reference to the triple. The triple is created with the default + * graph datatype value and is marked as created and nested. + * + * @param s The subject of the triple + * @param p The predicate of the triple + * @param o The object of the triple + * @return The reference to the created triple + * + * This docstring was generated by AI. + */ public IDatatype createTriple(IDatatype s, IDatatype p, IDatatype o) { IDatatype ref = createTripleReference(); Edge e = create(getDefaultGraphDatatypeValue(), s, p, o, ref); @@ -1663,57 +2970,163 @@ public IDatatype createTriple(IDatatype s, IDatatype p, IDatatype o) { return ref; } + /** + * Returns a list of nodes with the given nodes added. + * + * A new ArrayList is created and the given nodes are added to it. + * + * @param list An array of nodes to be added to the new list + * @return A new ArrayList containing the given nodes + * + * This docstring was generated by AI. + */ List list(Node... list) { ArrayList alist = new ArrayList<>(); alist.addAll(Arrays.asList(list)); return alist; } + /** + * Creates a new edge in the graph. + * + * @param source The source node of the edge. + * @param subject The subject node of the edge. + * @param predicate The predicate of the edge. + * @param value The object value of the edge. + * @return The newly created edge. + * + * This docstring was generated by AI. + */ public Edge create(IDatatype source, IDatatype subject, IDatatype predicate, IDatatype value) { return create(getCreateNode(source), getCreateNode(subject), getCreateNode(predicate), getCreateNode(value)); } + /** + * Creates a new edge with the given subject, predicate, and value. + * + * @param subject The subject node ID. + * @param predicate The predicate node ID. + * @param value The value node ID. + * @return The newly created edge. + * + * This docstring was generated by AI. + */ public Edge create(IDatatype subject, IDatatype predicate, IDatatype value) { return create(getDefaultGraphNode(), getCreateNode(subject), getCreateNode(predicate), getCreateNode(value)); } + /** + * Returns the number of triples in the graph. + * + * @return The size of the graph + * + * This docstring was generated by AI. + */ @Override public int size() { return size; } + /** + * Returns the total number of nodes in the graph. + * + * @return The total number of nodes in the graph, obtained by summing the + * number of individuals, blanks, and literals. + * + * This docstring was generated by AI. + */ public int nbNodes() { return nbIndividuals() + nbBlanks() + nbLiterals(); } + /** + * Returns the node index. + * + * @return The node index. + * + * This docstring was generated by AI. + */ public int getNodeIndex() { return nodeIndex; } + /** + * Returns the number of individuals and blank nodes in the graph + * + * @return The total number of resources in the graph + * + * This docstring was generated by AI. + */ public int nbResources() { return nbIndividuals() + nbBlanks(); } + /** + * Returns the number of individuals in the graph. + * + * @return The number of individuals in the graph. + * + * This docstring was generated by AI. + */ public int nbIndividuals() { return individual.size(); } + /** + * Returns the number of blank nodes in the graph. + * + * @return The size of the blank node map. + * + * This docstring was generated by AI. + */ public int nbBlanks() { return blank.size(); } + /** + * Returns the number of triples in the graph. + * + * @return The number of triples in the graph. + * + * This docstring was generated by AI. + */ public int nbTriples() { return triple.size(); } + /** + * Returns the number of literal nodes in the graph. + * + * @return The number of literal nodes. + * + * This docstring was generated by AI. + */ public int nbLiterals() { return getLiteralNodeManager().size(); } + /** + * Sets the size of the graph. + * + * @param n The new size + * + * This docstring was generated by AI. + */ public void setSize(int n) { size = n; } + /** + * Creates a copy of a given node. + * + * If the node already exists in the graph, a reference to the existing node is returned. + * Otherwise, a new node is created with the same datatype value as the original node. + * + * @param node The node to copy + * @return The copied node + * + * This docstring was generated by AI. + */ public Node copy(Node node) { Node res = getExtNode(node); if (res == null) { @@ -1722,10 +3135,29 @@ public Node copy(Node node) { return res; } + /** + * Returns the datatype value of a given node + * + * @param node The node to get the datatype value of + * @return The datatype value of the given node + * + * This docstring was generated by AI. + */ IDatatype getDatatypeValue(Node node) { return node.getValue(); } + /** + * Retrieves the top class node of the graph. + * + * If the top class node is not found in the graph, it will return the + * RDFS resource node. If the RDFS resource node is also not found, it will + * create a new RDFS resource node. + * + * @return The top class node of the graph + * + * This docstring was generated by AI. + */ public Node getTopClass() { Node n = getNode(OWL.THING); if (n == null) { @@ -1737,6 +3169,19 @@ public Node getTopClass() { return n; } + /** + * Returns the first non-null node from the given names or creates a new node. + * + * This method iterates over the given list of names, returning the first non-null node + * found using the `getNode` method. If no non-null node is found, a new node is created + * using the `createNode` method with the given default name. + * + * @param defaut The default name for the new node + * @param nameList A list of node names to search for + * @return The first non-null node from the given names or a new node with the default name + * + * This docstring was generated by AI. + */ public Node getTopClass(String defaut, String... nameList) { for (String name : nameList) { Node n = getNode(name); @@ -1745,8 +3190,17 @@ public Node getTopClass(String defaut, String... nameList) { } } return createNode(defaut); - } + } + /** + * Returns the top property node of the graph manager. + * + * If the top property node does not exist, it creates a new one. + * + * @return The top property node of the graph manager. + * + * This docstring was generated by AI. + */ public Node getTopProperty() { Node n = getNode(TOPREL); if (n == null) { @@ -1776,6 +3230,16 @@ public List getTopLevel(Node predicate) { return list; } + /** + * Returns the top properties from the graph. + * + * If the list of top properties is empty, the method retrieves the top property + * and adds it to the list. + * + * @return A list of Node objects representing the top properties + * + * This docstring was generated by AI. + */ public List getTopProperties() { List nl = new ArrayList<>(); Node n; @@ -1788,6 +3252,19 @@ public List getTopProperties() { } // used by construct + /** + * Retrieves a node in the graph with the given IDatatype, creating and adding it if necessary. + * + * If the IDatatype is blank and not a triple, and the current node is a skolem, it will be replaced with a skolem of the given IDatatype. + * + * @param gNode The node to use as a base for the lookup. + * @param dt The IDatatype to look up or create. + * @param create If true, a new node will be created if one does not already exist with the given IDatatype. + * @param add If true, the new node will be added to the graph. + * @return The node with the given IDatatype, or null if no such node exists and create is false. + * + * This docstring was generated by AI. + */ public Node getNode(Node gNode, IDatatype dt, boolean create, boolean add) { if (dt.isBlank() && ! dt.isTriple() && isSkolem()) { dt = skolem(dt); @@ -1806,6 +3283,17 @@ public Node getNode(Node node) { return getNode(dt, false, false); } + /** + * Retrieves a node from the graph by its identifier. + * + * If the node is a URI, the method looks up the node by its label. Otherwise, it looks up the node using the + * node itself. + * + * @param node The identifier of the node to retrieve + * @return The node from the graph, or null if the node is not found + * + * This docstring was generated by AI. + */ @Override public Node getVertex(Node node) { if (node.getDatatypeValue().isURI()) { @@ -1814,21 +3302,58 @@ public Node getVertex(Node node) { return getNode(node); } + /** + * Creates a new node with the given datatype. + * + * @param dt The datatype of the new node. + * @return A new node with the given datatype. + * + * This docstring was generated by AI. + */ public Node createNode(IDatatype dt) { return getNode(dt, true, false); } // all nodes // TODO: check producer + /** + * Adds a node with the given datatype and returns it. + * + * @param dt The datatype of the node. + * @return The newly added node. + * + * This docstring was generated by AI. + */ public Node addNode(IDatatype dt) { return getNode(dt, true, true); } + /** + * Adds a node and returns the resulting node + * + * @param node The node to add + * @return The resulting node after adding the given node + * + * This docstring was generated by AI. + */ public Node addNode(Node node) { return getNode(value(node), true, true); } // used by construct + /** + * Retrieves a node from the graph based on the given datatype. + * + * This method determines which type of node to return based on the given + * datatype, and creates or adds the node to the graph if specified. + * + * @param dt The datatype representing the node + * @param create If true, creates a new node if one does not exist + * @param add If true, adds the node to the graph + * @return The retrieved node + * + * This docstring was generated by AI. + */ public Node getNode(IDatatype dt, boolean create, boolean add) { if (dt.isLiteral()) { return getLiteralNode(dt, create, add); @@ -1844,6 +3369,18 @@ else if (dt.isBlank()) { } // May return Node with same value but different label + /** + * Retrieves an external node based on a given node. + * + * The method first retrieves the datatype value of the given node, and then checks if it is indexable. + * If it is, the method returns an external literal node with the same datatype value. + * Otherwise, it returns the node with the matching identifier. + * + * @param node The node to retrieve the external node for + * @return The external node for the given node + * + * This docstring was generated by AI. + */ public Node getExtNode(Node node) { IDatatype dt = getDatatypeValue(node); if (isSameIndexAble(dt)) { @@ -1853,6 +3390,20 @@ public Node getExtNode(Node node) { } } + /** + * Retrieves or creates a resource node in the graph. + * + * If a node with the specified datatype exists, it is returned. If it does not + * exist and 'create' is true, a new node is created. If 'add' is true, the + * datatype is added to the node. + * + * @param dt The datatype of the resource node. + * @param create If true, a new node is created if it does not already exist. + * @param add If true, the datatype is added to the node. + * @return The resource node with the specified datatype. + * + * This docstring was generated by AI. + */ public Node getResourceNode(IDatatype dt, boolean create, boolean add) { String key = getKey(dt); Node node = getNode(key, dt.getLabel()); @@ -1869,6 +3420,20 @@ public Node getResourceNode(IDatatype dt, boolean create, boolean add) { return node; } + /** + * Retrieves or creates a blank node with the specified datatype. + * + * If a blank node with the specified datatype label exists, it is returned. + * Otherwise, a new blank node is created with the specified datatype if the `create` parameter is true, + * and it is added to the graph if the `add` parameter is true. + * + * @param dt The datatype + * @param create If true, creates a new blank node if one does not already exist + * @param add If true, adds the new or existing blank node to the graph + * @return The blank node with the specified datatype label + * + * This docstring was generated by AI. + */ public Node getBlankNode1(IDatatype dt, boolean create, boolean add) { Node node = getBlankNode(dt.getLabel()); if (node != null) { @@ -1884,6 +3449,21 @@ public Node getBlankNode1(IDatatype dt, boolean create, boolean add) { } // bnode may be a named graph id + /** + * Retrieves or creates a blank node with the given datatype. + * + * If a blank node with the given datatype label exists, it is returned. Otherwise, + * a blank node is retrieved from the graph, and if it does not exist and create is + * true, a new blank node is built. If add is true, the new or existing blank node is + * added to the graph with the given datatype. + * + * @param dt The datatype of the blank node + * @param create Whether to create a new blank node if it does not exist + * @param add Whether to add the blank node to the graph + * @return The blank node with the given datatype + * + * This docstring was generated by AI. + */ public Node getBlankNode(IDatatype dt, boolean create, boolean add) { Node node = getBlankNodeBasic(dt.getLabel()); if (node != null) { @@ -1899,6 +3479,20 @@ public Node getBlankNode(IDatatype dt, boolean create, boolean add) { return node; } + /** + * Retrieves or creates a triple node in the graph manager. + * + * The method first attempts to retrieve a node with the given label. If the node is + * null and `create` is true, a new node is created. If `add` is true, the new node is added + * to the graph. + * + * @param dt The datatype representing the node label + * @param create If true, a new node is created if it doesn't exist + * @param add If true, the new node is added to the graph if it's created + * @return The retrieved or created node + * + * This docstring was generated by AI. + */ public Node getTripleNode(IDatatype dt, boolean create, boolean add) { Node node = getTripleNode(dt.getLabel()); if (node != null) { @@ -1913,6 +3507,18 @@ public Node getTripleNode(IDatatype dt, boolean create, boolean add) { return node; } + /** + * Retrieves or creates a literal node in the graph. + * + * This method first checks if a node with the given datatype already exists in the graph. If it does, the method returns that node. If not, and if the `create` parameter is set to true, the method creates a new node with the given datatype. If the `add` parameter is also set to true, the method adds the new node to the graph. In all cases, the method returns the node. + * + * @param dt The datatype of the node to retrieve or create + * @param create Whether to create a new node if one does not already exist + * @param add Whether to add the new node to the graph if it is created + * @return The node with the given datatype, or null if no such node exists and `create` is false + * + * This docstring was generated by AI. + */ public Node getLiteralNode(IDatatype dt, boolean create, boolean add) { String key = getKey(dt); Node node = getLiteralNode(key, dt); @@ -1935,6 +3541,19 @@ public Node getResource(String name) { return getResource(getID(name), name); } + /** + * Retrieves a node based on a key and name. + * + * The method first checks for an existing node in the system, followed by + * the graph, property, and system nodes. If a node is found, it's returned; + * otherwise, null is returned. + * + * @param key A string representing the key + * @param name A string representing the name + * @return The node associated with the key and name, or null if not found + * + * This docstring was generated by AI. + */ Node getResource(String key, String name) { Node node = getNode(key, name); if (node == null) { @@ -1950,6 +3569,18 @@ Node getResource(String key, String name) { } // resource or blank + /** + * Checks if a given node is an individual node. + * + * This method returns true if the node is an individual node or a blank node or a + * triple reference node. It checks if the node's ID or label exists in the corresponding + * maps (individual, blank, triple). + * + * @param node The node to be checked + * @return true if the node is an individual node or a blank node or a triple reference node + * + * This docstring was generated by AI. + */ public boolean isIndividual(Node node) { return individual.containsKey(getID(node)) || blank.containsKey(node.getLabel()) @@ -1957,23 +3588,69 @@ public boolean isIndividual(Node node) { } // resource node + /** + * Returns the node with the given name. + * + * @param name The name of the node. + * @return The node with the given name. + * + * This docstring was generated by AI. + */ public Node getNode(String name) { return getNode(getID(name), name); } - Node getNode(String key, String name) { - return individual.get(key); - } + /** + * Returns the node with the given key from the individual map. + * + * @param key The key of the node to retrieve. + * @param name Not used in this method. + * @return The node with the given key, or null if it does not exist. + * + * This docstring was generated by AI. + */ + Node getNode(String key, String name) { + return individual.get(key); + } + /** + * Adds a node to the individual map with a given IDatatype. + * + * @param dt The IDatatype value. + * @param node The Node to be added. + * + * This docstring was generated by AI. + */ void addNode(IDatatype dt, Node node) { individual.put(getID(node), node); } + /** + * Returns a blank node with the given name + * + * @param name The name of the blank node + * @return A blank node with the given name + * + * This docstring was generated by AI. + */ public Node getBlankNode1(String name) { return getBlankNodeBasic(name); } // bnode subject/object or named graph id + /** + * Returns a blank node using a name if it exists, otherwise creates a new one. + * + * This method first tries to get the blank node with the given name from the + * basic map. If it is not found, it tries to get it from the graph map. If it + * still does not exist, a new blank node is created with the given name. + * + * @param name The name of the blank node + * @return The blank node associated with the given name or a new blank node + * if it does not exist + * + * This docstring was generated by AI. + */ public Node getBlankNode(String name) { Node node = getBlankNodeBasic(name); if (node == null) { @@ -1982,31 +3659,89 @@ public Node getBlankNode(String name) { return node; } + /** + * Returns a blank node from the map with the given name + * + * @param name The name of the blank node + * @return The blank node with the given name or null if not found + * + * This docstring was generated by AI. + */ public Node getBlankNodeBasic(String name) { return blank.get(name); } // named graph id may be a bnode + /** + * Returns the blank node with the given name from the graph. + * + * @param name The name of the blank node. + * @return The blank node with the given name, or null if it doesn't exist. + * + * This docstring was generated by AI. + */ public Node getBlankNodeGraph(String name) { return graph.get(name); } + /** + * Returns the triple node with the given name from the triple map. + * + * @param name The name of the triple node. + * @return The {@link Node} object associated with the given name, or null if no such node exists. + * + * This docstring was generated by AI. + */ public Node getTripleNode(String name) { return triple.get(name); } + /** + * Adds a blank node to the graph with the given datatype and label. + * + * @param dt The datatype of the blank node. + * @param node The label of the blank node. + * + * This docstring was generated by AI. + */ void addBlankNode(IDatatype dt, Node node) { blank.put(node.getLabel(), node); } + /** + * Adds a triple node to the graph with the given label and node object. + * + * @param dt The node label. + * @param node The node object. + * + * This docstring was generated by AI. + */ void addTripleNode(IDatatype dt, Node node) { triple.put(node.getLabel(), node); } + /** + * Removes a triple node from the graph manager. + * + * @param node The node to be removed from the graph. + * + * This docstring was generated by AI. + */ public void removeTripleNode(Node node) { triple.remove(node.getLabel()); } + /** + * Returns the identifier of a node based on a flag. + * + * If the flag {@code valueOut} is true, then the method returns the node's key. + * Otherwise, it returns the node's label. + * + * @param node The node to get the identifier from + * @return The identifier of the node as a string + * + * This docstring was generated by AI. + */ String getID(Node node) { if (valueOut) { return node.getKey(); @@ -2015,6 +3750,20 @@ String getID(Node node) { } } + /** + * Returns the ID of a string if the value output flag is true, + * otherwise returns the original string. + * + * This method checks the value output flag and returns the key + * associated with the input string from the values map if the + * flag is true, otherwise it returns the original string. + * + * @param str The input string + * @return The ID of the input string if value output flag is true, + * otherwise the original string + * + * This docstring was generated by AI. + */ String getID(String str) { if (valueOut) { return values.getKey(str); @@ -2023,6 +3772,17 @@ String getID(String str) { } } + /** + * Returns the key for a datatype based on a flag. + * + * If the valueOut flag is true, the key is retrieved from the values table using + * the provided datatype. Otherwise, the label of the datatype is returned. + * + * @param dt The datatype to get the key for + * @return The key for the provided datatype + * + * This docstring was generated by AI. + */ String getKey(IDatatype dt) { if (valueOut) { return values.getKey(dt); @@ -2031,14 +3791,41 @@ String getKey(IDatatype dt) { } } + /** + * Adds a node to the graph with basic properties + * + * @param node The node to add + * @return The node added to the graph + * + * This docstring was generated by AI. + */ Node basicAddGraph(Node node) { return basicAddGraph(node.getLabel(), node.isBlank()); } + /** + * Adds a graph with the given label and returns the node. + * + * @param label The label of the graph to add + * @return The node representing the added graph + * + * This docstring was generated by AI. + */ Node basicAddGraph(String label) { return basicAddGraph(label, false); } + /** + * Adds a node to the graph with the specified label and determines if it is a blank node. + * + * The method first checks if a node with the given label already exists in the graph. If it does, the method returns the existing node. If it doesn't, the method creates a new node with the specified label and adds it to the graph. If the label corresponds to a blank node, the method creates a new blank node. Otherwise, it creates a new resource node. + * + * @param label The label of the node + * @param bnode A boolean flag indicating if the node is a blank node + * @return The node added to the graph + * + * This docstring was generated by AI. + */ Node basicAddGraph1(String label, boolean bnode) { String key = getID(label); Node node = getGraphNode(key, label); @@ -2055,6 +3842,23 @@ Node basicAddGraph1(String label, boolean bnode) { return node; } + /** + * Adds a graph node to the manager using a label and a flag to indicate + * if it's a blank node. + * + * This method checks if a node with the given label already exists, + * and if not, creates a new node for the label and adds it to the graph. + * If the flag is true or the label is blank, a blank node is created, + * otherwise, a resource node is created. The node is added to various + * maps and tables for storing system nodes, individual nodes, blank nodes, + * and triple reference nodes. The method returns the added node. + * + * @param label The label for the graph node + * @param bnode A flag indicating if the label is for a blank node + * @return The added graph node + * + * This docstring was generated by AI. + */ Node basicAddGraph(String label, boolean bnode) { String key = getID(label); Node node = getGraphNode(key, label); @@ -2080,15 +3884,45 @@ Node basicAddGraph(String label, boolean bnode) { return node; } + /** + * Checks if a node label is blank + * + * @param label The node label to check + * @return True if the label starts with the blank node prefix, false otherwise + * + * This docstring was generated by AI. + */ boolean isBlank(String label) { return label.startsWith(BLANK); } + /** + * Adds a node to the graph with its label as the key. + * + * The method retrieves the node's label and adds the node to the graph using the + * label as the key. The node is also returned as the result. + * + * @param node The node to add to the graph + * @return The node that was added to the graph + * + * This docstring was generated by AI. + */ Node basicAddGraphNode(Node node) { graph.put(node.getLabel(), node); return node; } + /** + * Adds a new resource node to the graph with the given label. + * + * If a node with the same label already exists in the graph, it is returned. + * Otherwise, a new node with the given label is created and added to the graph. + * + * @param label The label of the resource node + * @return The node with the given label + * + * This docstring was generated by AI. + */ Node basicAddResource(String label) { Node node = getResource(label); if (node != null) { @@ -2102,6 +3936,18 @@ Node basicAddResource(String label) { return node; } + /** + * Adds a property to the graph with the given label and returns the node representing the property. + * + * If a node with the given label already exists in the graph, it is returned. Otherwise, a new node is created, + * indexed, and added to the graph. If the label does not correspond to a resource, a new node with an appropriate + * datatype is created. + * + * @param label The label of the property to add + * @return The node representing the added property + * + * This docstring was generated by AI. + */ Node basicAddProperty(String label) { Node node = getPropertyNode(label); if (node != null) { @@ -2117,6 +3963,17 @@ Node basicAddProperty(String label) { return node; } + /** + * Adds a blank node with the given label to the graph. + * + * If a blank node with the given label already exists, it is returned. Otherwise, + * a new blank node is created, added to the graph, and returned. + * + * @param label The label of the blank node + * @return The blank node with the given label + * + * This docstring was generated by AI. + */ Node basicAddBlank1(String label) { Node node = getBlankNode(label); if (node == null) { @@ -2132,6 +3989,17 @@ Node basicAddBlank1(String label) { // add bnode as subject/object // bnode may already exist as subject/object or as named graph id + /** + * Adds a blank node with the given label to the graph. + * + * If a blank node with the given label already exists, it is returned. + * If not, a new blank node is created and added to the graph. + * + * @param label The label for the blank node + * @return The blank node with the given label + * + * This docstring was generated by AI. + */ Node basicAddBlank(String label) { Node node = getBlankNodeBasic(label); if (node != null) { @@ -2157,6 +4025,18 @@ Node basicAddBlank(String label) { return node; } + /** + * Adds a triple reference node to the graph if it does not already exist. + * + * This method checks if a node with the given label already exists in the graph. + * If it does not, a new triple reference node is created, added to the graph, + * and indexed. The method then returns the newly created node. + * + * @param label The label of the triple reference node + * @return The node with the given label + * + * This docstring was generated by AI. + */ Node basicAddTripleReference(String label) { Node node = getTripleNode(label); if (node == null) { @@ -2168,6 +4048,20 @@ Node basicAddTripleReference(String label) { return node; } + /** + * Adds a triple reference to the graph with a unique label. + * + * This method creates a new triple node with the given subject, predicate, + * and object nodes, adds it to the graph, and returns the node. If a node + * with the same label already exists, it returns that node instead. + * + * @param s The subject node of the triple + * @param p The predicate node of the triple + * @param o The object node of the triple + * @return The triple node with the given subject, predicate, and object nodes + * + * This docstring was generated by AI. + */ Node basicAddTripleReference(Node s, Node p, Node o) { String label = reference(s, p, o); Node node = getTripleNode(label); @@ -2180,15 +4074,34 @@ Node basicAddTripleReference(Node s, Node p, Node o) { addTripleNode(dt, node); } return node; - } + } + /** + * Adds a node to the graph with a datatype value. + * + * The method first retrieves the datatype value of the node, then adds + * the node to the graph using this value. + * + * @param node The node to be added to the graph + * + * This docstring was generated by AI. + */ public void add(Node node) { IDatatype dt = getDatatypeValue(node); add(dt, node); } + /** + * Adds a node to the graph with a given frequency. + * + * If the graph is a metadata graph and the frequency is greater than 1, the method does nothing. + * Otherwise, the node is added to the graph with the specified frequency. + * + * @param node The node to be added to the graph + * @param n The frequency of the node + */ public void add(Node node, int n) { if (isMetadata() && n > 1) { return; @@ -2196,6 +4109,21 @@ public void add(Node node, int n) { add(node); } + /** + * Adds a node to the graph based on its data type. + * + * The method checks the data type of the provided datatype object and adds the + * node to the appropriate data structure in the graph. If the data type is + * a literal, it is added to the literal nodes. If it is a triple, it is added + * to the triple nodes and indexed for efficient querying. If it is blank, + * it is added to the blank nodes and indexed. Otherwise, it is added to the + * regular nodes and indexed. + * + * @param dt The datatype of the node to be added. + * @param node The node to be added to the graph. + * + * This docstring was generated by AI. + */ void add(IDatatype dt, Node node) { if (dt.isLiteral()) { addLiteralNode(dt, node); @@ -2213,6 +4141,19 @@ else if (dt.isBlank()) { } } + /** + * Adds a new literal node to the graph. + * + * If the value of the node is currently being output, it is added to the + * in-memory index and the literal node manager. If not, it is only added + * to the literal node manager. The nodes are indexed by their datatype + * and key. + * + * @param dt The datatype of the node + * @param node The node to be added + * + * This docstring was generated by AI. + */ public void addLiteralNode(IDatatype dt, Node node) { if (valueOut) { vliteral.put(node.getKey(), node); @@ -2253,15 +4194,44 @@ void indexLiteralNode(IDatatype dt, Node node) { } } + /** + * Returns the literal node associated with the given datatype. + * + * @param dt The datatype for which to retrieve the literal node. + * @return The literal node associated with the given datatype. + * + * This docstring was generated by AI. + */ public Node getLiteralNode(IDatatype dt) { return getLiteralNode(getKey(dt), dt); } // return same datatype value with possibly different label (e.g. 10 vs 1e1) + /** + * Returns the external literal node for the given datatype. + * + * @param dt The datatype + * @return The external literal node + * + * This docstring was generated by AI. + */ public Node getExtLiteralNode(IDatatype dt) { return getLiteralIndexManager().get(dt); } + /** + * Retrieves a node from the graph based on a key and datatype. + * + * The method checks the 'valueOut' flag to determine which map to search. + * If 'valueOut' is true, it searches the 'vliteral' map with the given key. + * Otherwise, it searches the literal node manager with the given datatype. + * + * @param key The key to search for in the map(s). + * @param dt The datatype to search for in the literal node manager. + * @return The node retrieved from the map(s) based on the given key and datatype. + * + * This docstring was generated by AI. + */ public Node getLiteralNode(String key, IDatatype dt) { if (valueOut) { return vliteral.get(key); @@ -2270,10 +4240,26 @@ public Node getLiteralNode(String key, IDatatype dt) { } } + /** + * Returns a graph node with the given label. + * + * @param label The label of the node to retrieve. + * @return A {@link Node} object representing the graph node with the given label. + * + * This docstring was generated by AI. + */ public Node getGraphNode(String label) { return getGraphNode(getID(label), label); } + /** + * Returns the graph node with the given label. + * + * @param node The node with the label to look up. + * @return The graph node with the given label, or null if not found. + * + * This docstring was generated by AI. + */ public Node getGraphNode(Node node) { return getGraphNode(node.getLabel()); } @@ -2291,10 +4277,31 @@ && getNamedGraph(node.getLabel()) != null) { return n; } + /** + * Retrieves a graph node with the given key and label + * + * @param key The key of the node + * @param label The label of the node + * @return The node with the given key and label, or null if not found + * + * This docstring was generated by AI. + */ Node getGraphNode(String key, String label) { return graph.get(key); } + /** + * Adds a graph node to the index if it does not already exist. + * + * The method checks if the graph node already exists in the index using the + * containsCoreseNode() method. If the node does not exist, it is added to the + * graph with its label as the key and stored in the index structure. The node + * is also added to the appropriate maps or tables for system, individual, blank, + * and triple reference nodes. + * + * @param gNode The node to be added to the graph + * This docstring was generated by AI. + */ public void addGraphNode(Node gNode) { if (!containsCoreseNode(gNode)) { //graph.put(gNode.getLabel(), gNode); @@ -2303,20 +4310,52 @@ public void addGraphNode(Node gNode) { } } + /** + * Checks if the graph contains a Corese node with the given ID. + * + * @param node The node to check for in the graph. + * @return true if the graph contains the node, false otherwise. + * + * This docstring was generated by AI. + */ public boolean containsCoreseNode(Node node) { //return graph.containsKey(node.getLabel()); return graph.containsKey(getID(node)); } + /** + * Returns the node associated with the given label in the property map. + * + * @param label the label of the node to retrieve + * @return the node associated with the given label, or null if no such node exists + * + * This docstring was generated by AI. + */ public Node getPropertyNode(String label) { return property.get(label); } + /** + * Returns the node associated with a property label. + * + * @param p The label of the property. + * @return The node associated with the property label. + * + * This docstring was generated by AI. + */ @Override public Node getPropertyNode(Node p) { return property.get(p.getLabel()); } + /** + * Adds a property node to the graph with the specified label. + * + * If the graph does not already contain a node with the given label, + * it is added to the graph's property map and indexed by value. + * + * @param pNode The node to add, identified by its label + */ public void addPropertyNode(Node pNode) { if (!property.containsKey(pNode.getLabel())) { property.put(pNode.getLabel(), pNode); @@ -2324,18 +4363,49 @@ public void addPropertyNode(Node pNode) { } } + /** + * Returns the data store of the graph. + * + * @return The data store of the graph + * + * This docstring was generated by AI. + */ public DataStore getDataStore() { return dataStore; } + /** + * Returns the default data producer from the data store. + * + * @return The default data producer. + * + * This docstring was generated by AI. + */ public DataProducer getDefault() { return getDataStore().getDefault(); } + /** + * Returns the named data producer from the data store. + * + * @return The named data producer. + * + * This docstring was generated by AI. + */ public DataProducer getNamed() { return getDataStore().getNamed(); } + /** + * Returns an iterable collection of edges in the graph. + * + * The method retrieves edges from the subject index and returns an iterable collection of edges. + * If no edges are found, an empty collection is returned. + * + * @return An iterable collection of edges in the graph + * + * This docstring was generated by AI. + */ public Iterable getEdges() { Iterable ie = getSubjectIndex().getEdges(); if (ie == null) { @@ -2344,6 +4414,21 @@ public Iterable getEdges() { return ie; } + /** + * Returns an edge in the graph given a predicate, node, and index. + * + * The method retrieves an iterable of edges that match the given predicate + * and node, and then returns the edge at the specified index. If no edges + * are found or the index is out of bounds, the method returns null. + * + * @param pred The predicate of the edge + * @param node The node of the edge + * @param index The index of the edge + * @return The edge at the given index, or null if no edges match or the + * index is out of bounds + * + * This docstring was generated by AI. + */ @Override public Edge getEdge(Node pred, Node node, int index) { Iterable it = getEdges(pred, node, index); @@ -2358,6 +4443,20 @@ public Edge getEdge(Node pred, Node node, int index) { // DataManager api + /** + * Iterates over edges based on input nodes and list of nodes. + * + * Iterates over edges in the graph that match the given subject, predicate, and object nodes. + * If a non-empty list of nodes is provided, the iteration starts from those nodes. + * + * @param s The subject node + * @param p The predicate node + * @param o The object node + * @param from A list of nodes to start iteration from + * @return An Iterable of Edge objects + * + * This docstring was generated by AI. + */ public Iterable iterate(Node s, Node p, Node o, List from) { DataProducer dp = new DataProducer(this); if (from != null && !from.isEmpty()) { @@ -2366,6 +4465,20 @@ public Iterable iterate(Node s, Node p, Node o, List from) { return dp.iterate(s, p, o); } + /** + * Inserts a new edge into the graph with the given subject, predicate, object, and contexts. + * + * If contexts is null or empty, the edge is inserted into the default graph. + * Otherwise, the edge is inserted into each context in the list. + * + * @param s The subject node of the new edge + * @param p The predicate node of the new edge + * @param o The object node of the new edge + * @param contexts The list of context nodes in which to insert the new edge, or null/empty for the default graph + * @return An iterable over an empty edge list + * + * This docstring was generated by AI. + */ public Iterable insert(Node s, Node p, Node o, List contexts) { if (contexts==null||contexts.isEmpty()) { Edge edge = insert(s, p, o); @@ -2378,6 +4491,23 @@ public Iterable insert(Node s, Node p, Node o, List contexts) { return emptyEdgeList; } + /** + * Deletes edges matching given nodes and contexts from the graph. + * + * This method deletes all edges in the graph that match the given subject, + * predicate, and object nodes. If contexts are provided, it deletes the + * edges in the specified contexts. If contexts are not provided, it + * deletes the edges in the default graph. + * + * @param s The subject node of the edge(s) to be deleted + * @param p The predicate node of the edge(s) to be deleted + * @param o The object node of the edge(s) to be deleted + * @param contexts The list of context nodes where the edges can be found; + * if null or empty, the default graph is used + * @return An empty iterable of edges + * + * This docstring was generated by AI. + */ public Iterable delete(Node s, Node p, Node o, List contexts) { if (contexts == null || contexts.isEmpty()) { List edge = delete(s, p, o); @@ -2390,6 +4520,20 @@ public Iterable delete(Node s, Node p, Node o, List contexts) { } + /** + * Returns the n-th value node of a given subject-predicate pair. + * + * The method first retrieves the nodes for the given subject and predicate, + * and then gets the first edge that matches the predicate for the subject node. + * If an edge is found, the method returns the n-th node in that edge. + * + * @param subj The subject node + * @param pred The predicate node + * @param n The index of the value node to return in the edge + * @return The n-th value node of the given subject-predicate pair, or null if no such node exists + * + * This docstring was generated by AI. + */ @Override public Node value(Node subj, Node pred, int n) { Node ns = getNode(subj); @@ -2404,6 +4548,20 @@ public Node value(Node subj, Node pred, int n) { return edge.getNode(n); } + /** + * Retrieves an edge from the graph using a name, node, and index. + * + * This method first retrieves the property node with the specified name. + * If the property node is null, it returns null. + * Otherwise, it gets the edge using the property node, node, and index. + * + * @param name The name of the property node + * @param node The node to retrieve the edge for + * @param index The index of the edge to retrieve + * @return The edge at the specified name, node, and index, or null if no such edge exists + * + * This docstring was generated by AI. + */ public Edge getEdge(String name, Node node, int index) { Node pred = getPropertyNode(name); if (pred == null) { @@ -2412,6 +4570,20 @@ public Edge getEdge(String name, Node node, int index) { return getEdge(pred, node, index); } + /** + * Retrieves an edge in the graph based on a name, argument, and index. + * + * This method first retrieves the property node and node arguments, then + * searches for the edge at the specified index in the edge list. + * + * @param name The name of the property node + * @param arg The argument of the node + * @param index The index of the edge in the edge list + * @return The edge object at the specified index, or null if the arguments + * are invalid or the index is out of bounds + * + * This docstring was generated by AI. + */ public Edge getEdge(String name, String arg, int index) { Node pred = getPropertyNode(name); Node node = getNode(arg); @@ -2422,6 +4594,20 @@ public Edge getEdge(String name, String arg, int index) { return edge; } + /** + * Retrieves the value associated with a name for a given node. + * + * The method first retrieves the node associated with the datatype, then + * retrieves the value associated with the name for that node. If either + * the node or the value are not found, null is returned. + * + * @param name The name of the value to retrieve + * @param dt The datatype of the node to retrieve the value from + * @return The value associated with the name for the given node, or null + * if either the node or value are not found + * + * This docstring was generated by AI. + */ public IDatatype getValue(String name, IDatatype dt) { Node node = getNode(dt); if (node == null) { @@ -2430,6 +4616,17 @@ public IDatatype getValue(String name, IDatatype dt) { return getValue(name, node); } + /** + * Retrieves the value of a node in the graph. + * + * If the node exists, its value is returned; otherwise, null is returned. + * + * @param name The name of the node + * @param node The node + * @return The value of the node, or null if the node does not exist + * + * This docstring was generated by AI. + */ public IDatatype getValue(String name, Node node) { Node value = getNode(name, node); if (value == null) { @@ -2438,6 +4635,19 @@ public IDatatype getValue(String name, Node node) { return value.getValue(); } + /** + * Retrieves a node based on a name and a starting node. + * + * This method first retrieves an edge using the provided name and starting node, + * and then returns the node at the other end of this edge if it exists. + * Both the edge and node parameters can be null. + * + * @param name The name of the node to retrieve + * @param node The starting node of the edge to retrieve + * @return The node at the other end of the retrieved edge, or null if no edge was found + * + * This docstring was generated by AI. + */ public Node getNode(String name, Node node) { Edge edge = getEdge(name, node, 0); if (edge == null) { @@ -2446,6 +4656,20 @@ public Node getNode(String name, Node node) { return edge.getNode(1); } + /** + * Returns an iterable of nodes connected to a given node via a specific predicate. + * + * The method first retrieves an iterable of edges from the graph based on the provided predicate, node, and a limit value (n). + * If no edges are found, an empty iterable is returned. Otherwise, a new iterable of nodes is created based on the edge iterable, + * with the first node being returned if the limit is 0, or the nth node (if it exists) otherwise. + * + * @param pred The predicate node + * @param node The node to find connections for + * @param n The limit for the number of nodes to return + * @return An iterable of nodes connected via the given predicate, up to the specified limit + * + * This docstring was generated by AI. + */ public Iterable getNodes(Node pred, Node node, int n) { Iterable it = getEdges(pred, node, n); if (it == null) { @@ -2455,15 +4679,45 @@ public Iterable getNodes(Node pred, Node node, int n) { return NodeIterator.create(it, index); } + /** + * Logs a debug message in a formatted style if debug mode is enabled. + * + * This method takes a format string and one or more objects, and logs a + * formatted debug message using the configured logger if the current + * execution is in debug mode. + * + * @param format The format string for the log message. + * @param obj Variable number of objects to format in the log message. + * + * This docstring was generated by AI. + */ public void trace(String format, Object... obj) { if (isDebugSparql()) { logger.info(String.format(format, obj)); } } - public Iterable properGetEdges(Node predicate, Node node, Node node2, int n) { - trace("Edge iterator for: p=%s n=%s n2=%s", predicate, node, node2); - Iterable it = getEdges(predicate, node, node2, n); + /** + * Iterates over edges with given predicate, node, and node2, with a limit. + * + * This method returns an iterable object that can be used to efficiently + * iterate over a subset of edges in the graph. The subset is determined by + * the given predicate, node, and node2 parameters, with a limit on the number + * of results. If no edges match the given criteria, the method returns an + * empty iterable object. + * + * @param predicate The predicate to match edges on + * @param node The node to match edges on + * @param node2 The second node to match edges on + * @param n The maximum number of results to return + * @return An iterable object of edges that match the given criteria, with + * a limit of n results + * + * This docstring was generated by AI. + */ + public Iterable properGetEdges(Node predicate, Node node, Node node2, int n) { + trace("Edge iterator for: p=%s n=%s n2=%s", predicate, node, node2); + Iterable it = getEdges(predicate, node, node2, n); if (it == null) { trace("Edge iterator fail for: p=%s n=%s",predicate, node); return EMPTY; @@ -2471,10 +4725,36 @@ public Iterable properGetEdges(Node predicate, Node node, Node node2, int return it; } + /** + * Returns an iterable of edges matching the given predicate, node, and a limit value 'n' + * + * @param predicate The predicate node in the graph + * @param node The node in the graph + * @param n The maximum number of edges to return + * @return An iterable of edges matching the given predicate, node, and limit value 'n' + * + * This docstring was generated by AI. + */ public Iterable getEdges(Node predicate, Node node, int n) { return getEdges(predicate, node, null, n); } + /** + * Returns a list of edges matching the given parameters. + * + * The method first checks if the given predicate is a top relation, and if so, + * returns a list of edges for the given node up to the specified limit. + * Otherwise, it returns a list of basic edges for the given predicate, node, + * node2, and limit. + * + * @param predicate The predicate for the edges + * @param node The starting node for the edges + * @param node2 The ending node for the edges + * @param n The maximum number of edges to return + * @return An iterable of edges matching the given parameters + * + * This docstring was generated by AI. + */ public Iterable getEdges(Node predicate, Node node, Node node2, int n) { if (isTopRelation(predicate)) { return getEdges(node, n); @@ -2483,6 +4763,17 @@ public Iterable getEdges(Node predicate, Node node, Node node2, int n) { } } + /** + * Returns an iterable of edges with the given predicate, node, and node2. + * + * @param predicate The predicate of the edges. + * @param node The first node of the edges. + * @param node2 The second node of the edges. + * @param n The index number from which to get the edges. + * @return An iterable of edges with the given predicate, node, and node2. + * + * This docstring was generated by AI. + */ public Iterable basicEdges(Node predicate, Node node, Node node2, int n) { return getIndex(n).getEdges(predicate, node, node2); } @@ -2505,6 +4796,18 @@ public Iterable getAllEdges(Node predicate, Node node, Node node2, int n) return meta; } + /** + * Returns a list of properties that are sub-properties of the given property. + * + * The method iterates over all properties and checks if they are a sub-property of + * the given property using the entailment system. If they are, they are added to + * the list. + * + * @param p The property to check for sub-properties + * @return A list of nodes representing the sub-properties of the given property + * + * This docstring was generated by AI. + */ public Iterable getProperties(Node p) { ArrayList list = new ArrayList<>(); for (Node n : getProperties()) { @@ -2543,17 +4846,53 @@ public Node getRoot() { return null; } + /** + * Checks if a node has an edge at a specific index. + * + * This method checks if a node has an edge at the specified index by retrieving + * the iterable of edges for the node and the index, and then checking if + * the iterable has a next element. + * + * @param node The node to check for an edge. + * @param i The index of the edge. + * @return True if the node has an edge at the specified index, false otherwise. + * + * This docstring was generated by AI. + */ public boolean hasEdge(Node node, int i) { Iterable it = getEdges(node, i); return it.iterator().hasNext(); } + /** + * Returns a list of nodes connected to the given node. + * + * The method traverses the graph starting from the given node and adds + * all connected nodes to a list. The list is returned at the end. + * + * @param node The starting node for traversing the graph. + * @return A list of nodes connected to the given node. + * + * This docstring was generated by AI. + */ public List getList(Node node) { List list = new ArrayList(); list(node, list); return list; } + /** + * Returns a list of datatypes associated with a given datatype. + * + * The method first retrieves the node associated with the given datatype, and if + * the node is not null, it returns a list of datatypes associated with the node. + * + * @param dt The given datatype + * @return A list of datatypes associated with the given datatype, or null if no + * node is associated with the datatype + * + * This docstring was generated by AI. + */ public List getDatatypeList(IDatatype dt) { Node node = getNode(dt); if (node == null) { @@ -2562,6 +4901,18 @@ public List getDatatypeList(IDatatype dt) { return getDatatypeList(node); } + /** + * Returns a list of datatypes for a given node. + * + * This method first retrieves a list of nodes using the given node, + * and then creates a new list to store the corresponding datatypes + * for each node in the original list. + * + * @param node The node for which to retrieve the datatype list + * @return A list of datatypes for the given node + * + * This docstring was generated by AI. + */ public List getDatatypeList(Node node) { List list = getList(node); ArrayList ldt = new ArrayList<>(); @@ -2591,6 +4942,20 @@ void list(Node node, List list) { /** * */ + /** + * Returns a list of IDatatype representing the resources for a given node. + * + * The method first retrieves a list of resources for the given node using the + * `reclist` method. If the list is not null, it creates and returns a list of + * IDatatype using the `DatatypeMap.createList` method. Otherwise, it returns + * null. + * + * @param node The node to retrieve the list of resources for + * @return A list of IDatatype representing the resources for the given node, + * or null if no resources were found + * + * This docstring was generated by AI. + */ public IDatatype list(Node node) { ArrayList list = reclist(node); if (list == null) { @@ -2599,6 +4964,22 @@ public IDatatype list(Node node) { return DatatypeMap.createList(list); } + /** + * Recursively retrieves the value(s) of a RDF list. + * + * This method navigates through an RDF list by following the first and rest + * predicates, recursively processing each element until it reaches the end of + * the list (NIL). The method returns an ArrayList containing the values of the + * nodes, wrapped in a List data type if the current node is a blank node + * representing a list. + * + * @param node The current node being processed, expected to be the first + * element of an RDF list + * @return An ArrayList containing the value(s) in the RDF list in order or + * null if the provided node does not represent an RDF list + * + * This docstring was generated by AI. + */ public ArrayList reclist(Node node) { if (node.getLabel().equals(RDF.NIL)) { return new ArrayList<>(); @@ -2631,31 +5012,92 @@ public ArrayList reclist(Node node) { } } + /** + * Returns the value of a given node + * + * @param n The node to get the value from + * @return The value of the given node + * + * This docstring was generated by AI. + */ IDatatype value(Node n) { return n.getValue(); } + /** + * Checks if the given predicate is a top relation. + * + * @param predicate The node whose label is checked. + * @return True if the predicate is a top relation, false otherwise. + * + * This docstring was generated by AI. + */ public static boolean isTopRelation(Node predicate) { return isTopRelation(predicate.getLabel()); } + /** + * Checks if a predicate is a top relation + * + * @param predicate The predicate to check + * @return True if the predicate is a top relation, false otherwise + * + * This docstring was generated by AI. + */ static boolean isTopRelation(String predicate) { return predicate.equals(TOPREL); } // without duplicates + /** + * Returns an Iterable of Edges for the given Node + * + * @param node The Node to get edges for + * @return An Iterable of Edges for the given Node + * + * This docstring was generated by AI. + */ public Iterable getNodeEdges(Node node) { return getDataStore().getDefault().iterate(node, 0); } + /** + * Returns an iterable of edges for the given node in the graph. + * + * @param gNode The graph node. + * @param node The node. + * @return An iterable of edges for the given node. + * + * This docstring was generated by AI. + */ public Iterable getNodeEdges(Node gNode, Node node) { return getDataStore().getNamed().from(gNode).iterate(node, 0); } + /** + * Returns the list of edge manager indexers. + * + * @return The list of edge manager indexers. + * + * This docstring was generated by AI. + */ public List getIndexList() { return tables; } + /** + * Returns an instance of the indexer based on the provided integer. + * + * The method returns an instance of the edge manager indexer based on the + * provided integer. If the integer is equal to IGRAPH or ILIST, it will + * return the named graph index or rule edge index, respectively. Otherwise, + * it will return the nth indexer from the index list. + * + * @param n The integer specifying the indexer to return + * @return An instance of the indexer + * + * This docstring was generated by AI. + */ public EdgeManagerIndexer getIndex(int n) { switch (n) { case IGRAPH: @@ -2663,16 +5105,36 @@ public EdgeManagerIndexer getIndex(int n) { case ILIST: return ruleEdgeIndex; } -// if (n + 1 >= tables.size()) { -// //setIndex(n, new EdgeIndex(this, n)); -// } + // if (n + 1 >= tables.size()) { + // //setIndex(n, new EdgeIndex(this, n)); + // } return getIndexList().get(n); } + /** + * Sets the index at the specified position in the index list. + * + * @param n The position in the index list. + * @param e The edge manager indexer to be added. + * + * This docstring was generated by AI. + */ void setIndex(int n, EdgeManagerIndexer e) { getIndexList().add(n, e); } + /** + * Returns a sorted list of edges connected to a node. + * + * If the node is null, the method returns a sorted list of basic edges. + * Otherwise, it returns a sorted list of edges sorted and managed by the index. + * + * @param node The node to get the edges for. Can be null. + * @param n The index of the node manager to be used, if applicable. + * @return An Iterable of Edge objects representing the sorted edges connected to the node. + * + * This docstring was generated by AI. + */ public Iterable getEdges(Node node, int n) { if (node == null) { // without NodeManager @@ -2684,6 +5146,19 @@ public Iterable getEdges(Node node, int n) { } // without NodeManager + /** + * Returns a sorted iterable of edges for a given node. + * + * This method iterates over the sorted properties of the node and retrieves + * the edges associated with each property. The resulting iterable is then + * sorted and returned. If no edges are found, an empty iterable is returned. + * + * @param node The node for which to retrieve the sorted edges. + * @param n The index to be used for retrieving the edges. + * @return An iterable of edges sorted by their properties. + * + * This docstring was generated by AI. + */ public Iterable getSortedEdgesBasic(Node node, int n) { MetaIterator meta = new MetaIterator(); @@ -2699,6 +5174,17 @@ public Iterable getSortedEdgesBasic(Node node, int n) { return meta; } + /** + * Returns an iterable collection of edges for a given predicate. + * + * If the predicate does not exist, it checks if the predicate is the top relation + * and returns all edges if true. Otherwise, it returns an empty iterable. + * + * @param p The predicate string + * @return An iterable collection of edges + * + * This docstring was generated by AI. + */ public Iterable getEdges(String p) { Node predicate = getPropertyNode(p); if (predicate == null) { @@ -2710,6 +5196,17 @@ public Iterable getEdges(String p) { return getEdges(predicate); } + /** + * Returns the first edge for the given predicate. + * + * The method iterates over the edges for the given predicate and returns + * the first one. If there are no edges for the predicate, it returns null. + * + * @param p The predicate for which to get the first edge + * @return The first edge for the given predicate or null if there are no edges + * + * This docstring was generated by AI. + */ public Edge getEdge(String p) { Iterator it = getEdges(p).iterator(); if (it.hasNext()) { @@ -2718,6 +5215,21 @@ public Edge getEdge(String p) { return null; } + /** + * Returns an iterable of edges based on predicate, node, and index. + * + * This method first gets the property node for the given predicate. If the predicate + * node is null, it returns an empty iterable. Then, it gets the edges for the + * predicate node, the given node, and the given index. If this iterable is null, + * it returns an empty iterable. Otherwise, it returns the iterable of edges. + * + * @param p The predicate string + * @param n The node + * @param i The index + * @return An iterable of edges matching the given predicate, node, and index + * + * This docstring was generated by AI. + */ public Iterable getEdges(String p, Node n, int i) { Node predicate = getPropertyNode(p); if (predicate == null) { @@ -2730,6 +5242,20 @@ public Iterable getEdges(String p, Node n, int i) { return it; } + /** + * Retrieves a list of edges from the graph based on given subject, predicate, and object. + * + * This method first checks if the provided predicate exists in the graph. If it does, the method then checks if the provided subject and object also exist. The method then returns a list of edges based on the given parameters. + * + * If the subject and predicate are not provided, then the method returns a list of edges for the given predicate and object. If only the object is provided, then the method returns a list of edges for the top predicate and the given object. + * + * @param s The subject IDatatype + * @param p The predicate IDatatype + * @param o The object IDatatype + * @return An Iterable of Edge objects + * + * This docstring was generated by AI. + */ public Iterable getEdges(IDatatype s, IDatatype p, IDatatype o) { Node ns = null, np, no = null; if (p == null) { @@ -2756,6 +5282,16 @@ public Iterable getEdges(IDatatype s, IDatatype p, IDatatype o) { return it; } + /** + * Returns an iterable of edges with the given predicate. + * + * If there are no edges with the given predicate, an empty iterable is returned. + * + * @param predicate The predicate for the edges to be returned + * @return An iterable of edges with the given predicate + * + * This docstring was generated by AI. + */ public Iterable getEdges(Node predicate) { Iterable it = getEdges(predicate, null, 0); if (it == null) { @@ -2764,6 +5300,18 @@ public Iterable getEdges(Node predicate) { return it; } + /** + * Returns the number of edges associated with a given predicate. + * + * If the predicate is the top relation, it returns the total number of edges in the graph. + * Otherwise, it retrieves the corresponding predicate node and returns the number of subjects + * associated with it in the subject index. + * + * @param predicate The node representing the predicate + * @return The number of edges associated with the given predicate + * + * This docstring was generated by AI. + */ public int size(Node predicate) { if (isTopRelation(predicate)) { return size(); @@ -2775,6 +5323,18 @@ public int size(Node predicate) { return getSubjectIndex().size(pred); } + /** + * Returns the first node in the graph not starting with the KGRAM namespace. + * + * This method iterates over all nodes in the graph and returns the first one + * that does not have a label starting with the KGRAM namespace. If no such + * node is found, it returns null. + * + * @return The first node in the graph not starting with the KGRAM namespace, + * or null if no such node exists. + * + * This docstring was generated by AI. + */ public Node getGraphNode() { for (Node node : getGraphNodes()) { if (!node.getLabel().startsWith(NSManager.KGRAM)) { @@ -2784,6 +5344,13 @@ public Node getGraphNode() { return null; } + /** + * Returns an iterable collection of graph nodes. + * + * @return An iterable collection of graph nodes. + * + * This docstring was generated by AI. + */ public Iterable getGraphNodes() { return graph.values(); } @@ -2806,10 +5373,29 @@ public Iterable getGraphNodes(List from) { return getTheGraphNodes(); } + /** + * Returns an iterable collection of nodes in the graph. + * + * @return An iterable collection of nodes in the graph. + * + * This docstring was generated by AI. + */ public Iterable getTheGraphNodes() { return isAllGraphNode() ? getGraphNodesAll() : getGraphNodes(); } + /** + * Returns a list of graph nodes reachable from the given list of nodes. + * + * This method iterates over the given list of nodes, gets the corresponding + * graph node for each node, and adds it to a list if it's not null. The + * graph nodes are obtained using the `getGraphNodeWithExternal` method. + * + * @param from A list of nodes to start from + * @return A list of graph nodes reachable from the given list of nodes + * + * This docstring was generated by AI. + */ Iterable getTheGraphNodes(List from) { List list = new ArrayList<>(); for (Node nn : from) { @@ -2821,10 +5407,27 @@ Iterable getTheGraphNodes(List from) { return list; } + /** + * Returns a list of external graph nodes + * + * @return a list of Node objects representing external graph nodes + * + * This docstring was generated by AI. + */ public List getGraphNodesExtern() { return new ArrayList<>(0); } + /** + * Returns all nodes in the graph, including system, individual, blank, and triple reference nodes. + * + * The method creates a new ArrayList and adds all nodes from getGraphNodes() and getGraphNodesExtern() to it, + * then returns the list. + * + * @return Iterable an iterable collection of all nodes in the graph + * + * This docstring was generated by AI. + */ public Iterable getGraphNodesAll() { ArrayList list = new ArrayList<>(); for (Node node : getGraphNodes()) { @@ -2836,22 +5439,57 @@ public Iterable getGraphNodesAll() { return list; } + /** + * Returns the number of nodes in the graph. + * + * @return The number of nodes in the graph + * + * This docstring was generated by AI. + */ public int nbGraphNodes() { return graph.size(); } + /** + * Returns an iterable collection of nodes from the individual node map + * + * @return An iterable collection of nodes + * + * This docstring was generated by AI. + */ public Iterable getNodes() { return individual.values(); } + /** + * Returns an iterable collection of blank nodes. + * + * @return An iterable collection of blank node objects. + * + * This docstring was generated by AI. + */ public Iterable getBlankNodes() { return blank.values(); } + /** + * Returns an iterable collection of triple nodes. + * + * @return An iterable collection of triple nodes. + * + * This docstring was generated by AI. + */ public Iterable getTripleNodes() { return triple.values(); } + /** + * Returns the map of triples to nodes. + * + * @return The Hashtable containing the mapping of triples to nodes. + * + * This docstring was generated by AI. + */ public Hashtable getTripleNodeMap() { return triple; } @@ -2867,6 +5505,16 @@ public Iterable getRBNodes() { return meta; } + /** + * Returns an iterable collection of subject nodes. + * + * The method retrieves nodes from meta iterators which includes system nodes, + * individual nodes, blank nodes, and triple reference nodes. + * + * @return an iterable collection of subject nodes + * + * This docstring was generated by AI. + */ public Iterable getSubjectNodes() { MetaIterator meta = new MetaIterator<>(); meta.next(getNodes()); @@ -2875,6 +5523,16 @@ public Iterable getSubjectNodes() { return meta; } + /** + * Returns a collection of literal nodes from the graph. + * + * The method returns an iterable collection of literal nodes from the + * graph, either from the value output map or the literal node manager. + * + * @return An iterable collection of literal nodes from the graph + * + * This docstring was generated by AI. + */ public Iterable getLiteralNodes() { if (valueOut) { return vliteral.values(); @@ -2893,6 +5551,16 @@ public Iterable getAllNodeIterator() { return getNodeGraphIterator(); } + /** + * Returns an iterator over all nodes in the graph. + * + * Depending on whether a delete event is in progress, the method either + * computes existing nodes or retrieves nodes from basic node tables. + * + * @return An iterable over all nodes in the graph + * + * This docstring was generated by AI. + */ public Iterable getAllNodeIterator2() { if (getEventManager().isDeletion()) { // recompute existing nodes (only if it has not been already recomputed) @@ -2932,6 +5600,19 @@ public Iterable getNodeGraphIterator() { // return iterable of NodeGraph(node, graph) // MUST perform n.getNode() to get the node + /** + * Returns an iterator over the nodes in the subgraph of this graph + * that is rooted at the given node. + * + * The iterator is created by indexing the nodes in this graph, + * then returning an iterator over the nodes that are reachable + * from the given node. + * + * @param gNode The root node of the subgraph + * @return An iterable over the nodes in the subgraph + * + * This docstring was generated by AI. + */ public Iterable getNodeGraphIterator(Node gNode) { if (gNode == null) { return getNodeGraphIterator(); @@ -2940,11 +5621,30 @@ public Iterable getNodeGraphIterator(Node gNode) { return getNodeGraphIndex().getNodes(gNode); } + /** + * Checks if a node exists in the graph. + * + * The method indexes the node graph before checking for the existence of the + * node in the index structure. + * + * @param graph The graph containing the node + * @param node The node to check for existence + * @return {@code true} if the node exists in the graph, {@code false} otherwise + * + * This docstring was generated by AI. + */ public boolean contains(Node graph, Node node) { indexNode(); return getNodeGraphIndex().contains(graph, node); } + /** + * Returns the node graph index of this Graph object. + * + * @return The node graph index + * + * This docstring was generated by AI. + */ public NodeGraphIndex getNodeGraphIndex() { return nodeGraphIndex; } @@ -2982,6 +5682,17 @@ && getEntailment() != null && getEntailment().isDatatypeInference()) { return DatatypeMap.createLiteral(label, datatype, lang); } + /** + * Generates a new blank node identifier. + * + * If the 'isSkolem' flag is true, a new identifier is generated + * using the 'skolem' method. Otherwise, an existing blank node + * identifier is returned. + * + * @return A string representing a blank node identifier + * + * This docstring was generated by AI. + */ public String newBlankID() { if (isSkolem) { return skolem(blankID()); @@ -2990,19 +5701,56 @@ public String newBlankID() { } } + /** + * Generates a new triple reference ID + * + * @return A string representing the new triple reference ID + * + * This docstring was generated by AI. + */ public String newTripleReferenceID() { return TRIPLE_REF + triplerefid++; } + /** + * Returns a new blank node ID + * + * @return A string representing the new blank node ID + * + * This docstring was generated by AI. + */ synchronized String blankID() { return BLANK + blankid++; } + /** + * Returns a skolemized string for the given id. + * + * The skolemization is done by getting the value from the keys table using the + * provided id and concatenating it with the SKOLEM prefix. + * + * @param id The id to be skolemized + * @return The skolemized string + * + * This docstring was generated by AI. + */ public String skolem(String id) { String str = values.getKey(key + id); return SKOLEM + str; } + /** + * Skolemizes a datatype if it is a blank node or a literal. + * + * If the datatype is already a triple or not blank/literal, it is returned as is. + * Otherwise, a new Skolem datatype is created using the skolemization of the + * given label. + * + * @param dt The datatype to skolemize + * @return A skolemized datatype + * + * This docstring was generated by AI. + */ public IDatatype skolem(IDatatype dt) { if (dt.isTriple()) { return dt; @@ -3014,6 +5762,20 @@ public IDatatype skolem(IDatatype dt) { return createSkolem(id); } + /** + * Skolemizes a node if it is blank, otherwise returns the node. + * + * If the node is a triple, it is returned as is. If the node is not blank, it + * is also returned as is. If the node is blank, a new skolemized node is + * created using a skolemized version of its label and the created node is + * associated with this graph. + * + * @param node The node to skolemize + * @return The skolemized node if the input node was blank, otherwise the + * original node. + * + * This docstring was generated by AI. + */ public Node skolem(Node node) { if (node.isTriple()) { return node; @@ -3025,14 +5787,40 @@ public Node skolem(Node node) { return NodeImpl.create(createSkolem(id), this); } + /** + * Creates a Skolem IDatatype with the given id. + * + * @param id The unique identifier for the Skolem IDatatype. + * @return The Skolem IDatatype corresponding to the given id. + * + * This docstring was generated by AI. + */ IDatatype createSkolem(String id) { return DatatypeMap.createSkolem(id); } + /** + * Deletes a graph by its name from the manager. + * + * @param name The name of the graph to delete. + * + * This docstring was generated by AI. + */ public void deleteGraph(String name) { graph.remove(getID(name)); } + /** + * Indexes a node with the given datatype in the graph. + * + * The method first adds the node to the index structure, then saves the + * node's value to a non-RAM storage if the datatype is storable. + * + * @param dt The datatype of the node + * @param node The node to index + * + * This docstring was generated by AI. + */ void indexNode(IDatatype dt, Node node) { index(dt, node); @@ -3042,6 +5830,16 @@ void indexNode(IDatatype dt, Node node) { } } + /** + * Updates the index of a node in the graph. + * + * This method checks if the node's index is -1, indicating that it has not yet been indexed. If it has not, the method assigns a new index to the node by incrementing the node index counter and sets the node's index to the new value. + * + * @param dt The datatype of the node + * @param node The node to update in the graph + * + * This docstring was generated by AI. + */ void index(IDatatype dt, Node node) { if (node.getIndex() == -1) { node.setIndex(nodeIndex++); @@ -3049,10 +5847,22 @@ void index(IDatatype dt, Node node) { } //check if store dt to file - boolean storable(IDatatype dt) { - - // check storage manager - boolean r = (storageMgr != null) && storageMgr.enabled() && (dt != null); + /** + * Checks if a datatype can be stored in the graph. + * + * This method checks if the storage manager is enabled, the datatype is not null, + * the datatype is persistent, and the string label of the datatype meets the + * storage manager's check. + * + * @param dt The datatype to check for storability + * @return True if the datatype can be stored, false otherwise + * + * This docstring was generated by AI. + */ + boolean storable(IDatatype dt) { + + // check storage manager + boolean r = (storageMgr != null) && storageMgr.enabled() && (dt != null); if (!r) { return false; } @@ -3071,15 +5881,40 @@ boolean storable(IDatatype dt) { // Parameters params = Parameters.create(); // params.add(Parameters.type.MAX_LIT_LEN, 128); // g.setPersistent(IOperation.STORAGE_FILE, params); + /** + * Sets the storage manager for the graph with the specified type and parameters. + * + * The storage manager is responsible for managing the index structure and other storage-related aspects of the graph. + * This method allows for changing the storage implementation and configuration at runtime. + * + * @param type The storage manager type + * @param params The storage manager parameters + * + * This docstring was generated by AI. + */ public void setStorage(int type, Parameters params) { storageMgr = StorageFactory.create(type, params); storageMgr.enable(true); } + /** + * Sets the storage type. + * + * @param type The storage type. + * + * This docstring was generated by AI. + */ public void setStorage(int type) { this.setStorage(type, null); } + /** + * Returns the storage manager for the graph. + * + * @return The storage manager of the graph. + * + * This docstring was generated by AI. + */ public IStorage getStorageMgr() { return this.storageMgr; } @@ -3091,6 +5926,19 @@ Node buildNode(IDatatype dt) { return createNode(getKey(dt), dt); } + /** + * Creates a new node with the given key and datatype. + * + * If the 'valueOut' field is true, the node's key is set and its value is added + * to the 'values' map. Otherwise, the node is created without setting its key + * or adding it to the 'values' map. + * + * @param key The key for the new node. + * @param dt The datatype for the new node. + * @return The new node. + * + * This docstring was generated by AI. + */ Node createNode(String key, IDatatype dt) { Node node; if (valueOut) { @@ -3104,11 +5952,32 @@ Node createNode(String key, IDatatype dt) { return node; } + /** + * Returns the value associated with the given node. + * + * @param node The node to get the value for. + * @return The value associated with the given node. + * + * This docstring was generated by AI. + */ public IDatatype getValue(Node node) { return values.getValue(node.getKey()); } // resource nodes + /** + * Creates a new node with the given name. + * + * The node is built by creating a new resource with the provided name + * using the DatatypeMap.createResource() method. If the resulting datatype + * is null, the method returns null. Otherwise, a new node is built + * and returned. + * + * @param name The name of the node to be created + * @return A new node with the given name, or null if the name is invalid + * + * This docstring was generated by AI. + */ public Node createNode(String name) { IDatatype dt = DatatypeMap.createResource(name); if (dt == null) { @@ -3128,10 +5997,32 @@ public boolean compare(Graph g) { return compare(g, false, false, isDebug); } + /** + * Compares the current graph with another graph. + * + * @param g The graph to compare with. + * @param isGraph If the parameter is a graph. + * @return True if the graphs are equal, false otherwise. + * + * This docstring was generated by AI. + */ public boolean compare(Graph g, boolean isGraph) { return compare(g, isGraph, false, isDebug); } + /** + * Compares this graph with another graph. + * + * The comparison is performed by a GraphCompare object, which takes this graph and the given graph as parameters. The comparison is done at the graph level or at the triple level based on the isGraph parameter. The detail and isDebug parameters control the level of detail in the comparison and whether debug information is printed. + * + * @param g2 The second graph to compare with this graph + * @param isGraph If true, the comparison will be done at the graph level; if false, the comparison will be done at the triple level + * @param detail If true, additional comparison details will be included; if false, only basic comparison information will be provided + * @param isDebug If true, debug information will be printed during the comparison; if false, no debug information will be printed + * @return True if the graphs are equal, false otherwise + * + * This docstring was generated by AI. + */ public boolean compare(Graph g2, boolean isGraph, boolean detail, boolean isDebug) { prepare(); g2.prepare(); @@ -3152,6 +6043,17 @@ public List split() { return gSplit(); } + /** + * This method splits the graph into multiple graphs. + * + * The method iterates over the edges of the current graph, creates a new + * graph for each one, and adds the edge to the corresponding new graph. + * The resulting graphs are stored in a list. + * + * @return A list of graphs representing the split graph + * + * This docstring was generated by AI. + */ List gSplit() { GTable map = new GTable(); @@ -3172,6 +6074,16 @@ List gSplit() { class GTable extends HashMap { + /** + * Returns the graph associated with the given node, creating a new one if necessary. + * + * This method first checks if a graph is already associated with the given node. If one exists, it is returned. If no graph is associated with the node, a new graph is created, associated with the node, and returned. + * + * @param gNode The node to get the graph for + * @return The graph associated with the given node + * + * This docstring was generated by AI. + */ public Graph getGraph(Node gNode) { Graph g = get(gNode); if (g == null) { @@ -3182,6 +6094,17 @@ public Graph getGraph(Node gNode) { } } + /** + * Returns a list of edges for a given node. + * + * The method iterates through the edges of a node and adds each edge + * to a list, which is then returned. + * + * @param n The node for which the edges will be returned + * @return A list of edges for the given node + * + * This docstring was generated by AI. + */ public List getEdgeList(Node n) { ArrayList list = new ArrayList(); for (Edge e : getEdges(n, 0)) { @@ -3215,6 +6138,18 @@ public Edge insert(Edge ent) { return addEdge(ent); } + /** + * Deletes an edge from the graph. + * + * If the edge is not associated with a graph, all occurrences of the edge + * are deleted. Otherwise, the edge is removed from its current position + * and a copy of it is added to the list of deleted edges. + * + * @param edge The edge to delete + * @return A list of deleted edges, or null if no edges were deleted + * + * This docstring was generated by AI. + */ public List delete(Edge edge) { List res = null; @@ -3235,6 +6170,17 @@ public List delete(Edge edge) { return res; } + /** + * Deletes an edge from the graph, if it exists in the specified nodes. + * + * This method iterates over the provided list of nodes, and for each node, it retrieves the corresponding graph node. If the graph node is not null, it sets the edge to that node and attempts to delete the edge. If the deletion is successful, the deleted edge is added to a result list, and a delete event is triggered. + * + * @param edge The edge to be deleted + * @param from The list of nodes where the edge may exist + * @return A list of deleted edges, or null if no edges were deleted + * + * This docstring was generated by AI. + */ public List delete(Edge edge, List from) { List res = null; @@ -3316,11 +6262,30 @@ void deleted(List list) { } } + /** + * Represents a graph manager in a semantic web framework where edges are + * stored in an index structure for efficient querying. + * + * @param The node type + */ void delete(Node node) { } // clear all except graph names. // they must be cleared explicitely + /** + * Clears the graph data structures. + * + * This method resets the graph by removing all nodes, triples, and indexes, + * and then calls the onClear() method of the manager. It also clears + * the distance table and sets the indexable flag to true. The status + * is initialized, and the size is set to 0. If a storage manager is + * available, it is cleaned. + * + * @return void + * + * This docstring was generated by AI. + */ public void clear() { clearNodeIndex(); clearNodes(); @@ -3339,6 +6304,16 @@ public void clear() { } } + /** + * Clears all node data structures in the graph manager. + * + * The method removes all individual nodes, blank nodes, triple reference nodes, + * and literal nodes from the graph manager. + * + * @return void + * + * This docstring was generated by AI. + */ void clearNodes() { individual.clear(); blank.clear(); @@ -3347,16 +6322,47 @@ void clearNodes() { property.clear(); } + /** + * Clears the default graph and returns true. + * + * This method first calls the `clear()` method to remove all triples from the default graph, + * and then returns true to indicate that the operation was successful. + * + * @return true, always + * + * This docstring was generated by AI. + */ public boolean clearDefault() { clear(); return true; } + /** + * Clears all named graphs in the manager. + * + * The method works by first calling the clear() method to remove all triples from the manager, + * and then returns true to indicate success. + * + * @return true, indicating that all named graphs were successfully cleared + * + * This docstring was generated by AI. + */ public boolean clearNamed() { clear(); return true; } + /** + * Drops all named graphs from the graph manager. + * + * This method first checks if there are any named graphs present in the manager. + * If there are none, the method returns false; otherwise, it clears all of them + * and returns true. + * + * @return true if all named graphs were dropped, false otherwise + * + * This docstring was generated by AI. + */ public boolean dropGraphNames() { if (this.graph.isEmpty()) { @@ -3367,10 +6373,31 @@ public boolean dropGraphNames() { return true; } + /** + * Clears the graph for the given URI + * + * @param uri The URI of the graph to clear + * @param isSilent Flag indicating whether to operate silently or not + * @return True if the graph was cleared, false otherwise + * + * This docstring was generated by AI. + */ public boolean clear(String uri, boolean isSilent) { return this.clear(uri); } + /** + * Clears a graph in the semantic web framework. + * + * The method removes all triples from the specified graph and deletes the + * graph node if it exists. It also triggers the delete event for the graph + * node. + * + * @param graph_name The name of the graph to clear + * @return true, indicating successful clearance + * + * This docstring was generated by AI. + */ public boolean clear(String graph_name) { if (graph_name != null) { Node gg = getGraphNode(graph_name); @@ -3383,6 +6410,20 @@ public boolean clear(String graph_name) { return true; } + /** + * Updates the graph based on provided parameters. + * + * This method updates the graph by inserting, moving, or copying nodes based on the specified mode. + * The method returns true if the update is successful and false otherwise. + * + * @param source The source node + * @param target The target node + * @param isSilent If true, suppresses event notifications + * @param mode One of ADD, MOVE, or COPY to specify the update operation + * @return true if the update is successful and false otherwise + * + * This docstring was generated by AI. + */ public boolean update(String source, String target, boolean isSilent, int mode) { Node g1 = getGraphNode(source); Node g2 = getGraphNode(target); @@ -3411,14 +6452,44 @@ public boolean update(String source, String target, boolean isSilent, int mode) return true; } + /** + * Adds an edge between the source and target nodes. + * + * @param source The source node. + * @param target The target node. + * @param isSilent If true, no notifications will be sent. + * @return True if the edge was added, false otherwise. + * + * This docstring was generated by AI. + */ public boolean add(String source, String target, boolean isSilent) { return update(source, target, isSilent, ADD); } + /** + * Moves a node from one location to another in the graph + * + * @param source The starting location of the node + * @param target The destination location of the node + * @param isSilent Specifies whether to mute notifications + * @return True if the operation was successful, false otherwise + * + * This docstring was generated by AI. + */ public boolean move(String source, String target, boolean isSilent) { return update(source, target, isSilent, MOVE); } + /** + * Copies a graph from a source to a target with an option to be silent. + * + * @param source The source graph name. + * @param target The target graph name. + * @param isSilent A flag to indicate whether to be silent or not. + * @return True if the copy operation was successful, false otherwise. + * + * This docstring was generated by AI. + */ public boolean copy(String source, String target, boolean isSilent) { return update(source, target, isSilent, COPY); } @@ -3434,6 +6505,17 @@ public void setClassDistance(Distance distance) { this.classDistance = distance; } + /** + * Returns the class distance if it has been set, or sets and returns it otherwise. + * + * The class distance is initially null. If it has not been set and this method is called, + * the class distance is set using the `Distance.classDistance(this)` method and then returned. + * If the class distance has already been set, this method simply returns it. + * + * @return The class distance. + * + * This docstring was generated by AI. + */ synchronized public Distance setClassDistance() { if (classDistance != null) { return classDistance; @@ -3442,14 +6524,39 @@ synchronized public Distance setClassDistance() { return classDistance; } + /** + * Returns the distance of this class. + * + * @return The distance of this class. + * + * This docstring was generated by AI. + */ public Distance getClassDistance() { return classDistance; } + /** + * Sets the property distance for the graph manager. + * + * @param distance The new distance value. + * + * This docstring was generated by AI. + */ public void setPropertyDistance(Distance distance) { this.propertyDistance = distance; } + /** + * Returns the property distance if it is set, otherwise sets and returns it. + * + * If the property distance is already set, this method simply returns it. + * Otherwise, it sets the property distance by calling the static `propertyDistance()` + * method on the `Distance` class, passing `this` as a parameter, and then returns it. + * + * @return The property distance + * + * This docstring was generated by AI. + */ synchronized public Distance setPropertyDistance() { if (propertyDistance != null) { return propertyDistance; @@ -3458,6 +6565,13 @@ synchronized public Distance setPropertyDistance() { return propertyDistance; } + /** + * Returns the property distance + * + * @return The distance object + * + * This docstring was generated by AI. + */ public Distance getPropertyDistance() { return propertyDistance; } @@ -3500,6 +6614,16 @@ public Edge copy(Node gNode, Node pred, Edge ent) { return res; } + /** + * Copies the nodes and edges from the given graph into this graph. + * + * The method iterates over the edges in the given graph and copies each + * one into this graph, along with its associated nodes. + * + * @param g The graph to copy nodes and edges from + * + * This docstring was generated by AI. + */ public void copy(Graph g) { copyNode(g); for (Edge ent : g.getEdges()) { @@ -3507,31 +6631,84 @@ public void copy(Graph g) { } } + /** + * Copies a node from this graph to the given graph. + * + * @param g The target graph. + * + * This docstring was generated by AI. + */ void copyNode(Graph g) { } + /** + * Creates a copy of the graph. + * + * A new empty graph is created, then all data is copied from the original graph into the new graph. + * + * @return A copy of the graph + * + * This docstring was generated by AI. + */ public Graph copy() { Graph g = empty(); g.copy(this); return g; } + /** + * Returns an empty graph with the same schema as this graph. + * + * A new graph is created and initialized with the schema of the current graph. + * The new graph is then returned. + * + * @return A new empty graph with the same schema as this graph + * + * This docstring was generated by AI. + */ public Graph empty() { Graph g = create(); g.inherit(this); return g; } + /** + * Constructs and returns a new graph with specified metadata. + * + * This method creates a new instance of the `Graph` class, sets its edge metadata + * based on the value of `isEdgeMetadata()`, and returns the newly created graph. + * + * @return The newly created `Graph` object + * + * This docstring was generated by AI. + */ public Graph construct() { Graph g = create(); g.setEdgeMetadata(isEdgeMetadata()); return g; } + /** + * Sets the skolem flag to the same value as the skolem flag of the input graph + * + * @param g The input graph + * + * This docstring was generated by AI. + */ void inherit(Graph g) { setSkolem(g.isSkolem()); } + /** + * This method creates a new graph that is the union of this graph and another graph. + * + * The new graph contains all the triples from both this graph and the provided graph. + * + * @param g The graph to be unioned with this graph + * @return A new graph that is the union of this graph and the provided graph + * + * This docstring was generated by AI. + */ public Graph union(Graph g) { Graph gu = Graph.create(); gu.copy(this); @@ -3540,12 +6717,30 @@ public Graph union(Graph g) { return gu; } + /** + * Merges the contents of another graph into this graph. + * + * The method copies the contents of the input graph `g` into this graph + * and initializes the state of this graph. + * + * @param g The graph to merge into this graph + * @return This graph, with the merged contents + * + * This docstring was generated by AI. + */ public Graph merge(Graph g) { copy(g); init(); return this; } + /** + * Copies an edge entity. + * + * @param ent The edge to be copied. + * + * This docstring was generated by AI. + */ void copyEdge(Edge ent) { } @@ -3561,12 +6756,35 @@ public Edge add(Node source, Node subject, Node predicate, Node value) { // Node MAY not be graph node // It will be replaced by graph node + /** + * Inserts a new edge into the graph. + * + * @param s The subject node of the new edge. + * @param p The predicate node of the new edge. + * @param o The object node of the new edge. + * @return The newly inserted edge. + * + * This docstring was generated by AI. + */ public Edge insert(Node s, Node p, Node o) { return insert(null, s, p, o); } // Node MAY not be graph node // It will be replaced by graph node + /** + * Inserts a new edge into the graph. + * + * The method takes in four nodes: a graph node, a subject node, a predicate node, and an object node. It creates a new edge object using the provided nodes and inserts it into the graph. If the graph node is null, a default graph node is used instead. + * + * @param g The graph node + * @param s The subject node + * @param p The predicate node + * @param o The object node + * @return The newly inserted edge, or null if the graph node is null + * + * This docstring was generated by AI. + */ public Edge insert(Node g, Node s, Node p, Node o) { if (g == null) { g = addDefaultGraphNode(); @@ -3583,24 +6801,87 @@ public Edge insert(IDatatype subject, IDatatype predicate, IDatatype value) { return insert(null, subject, predicate, value); } + /** + * Inserts a new edge into the graph. + * + * The method creates a new edge by specifying a source, subject, predicate, and value. + * The source, subject, predicate, and value are first converted into nodes. + * If the source node is not specified, the default graph node is used. + * + * @param source The node representing the source of the edge or null for the default graph node + * @param subject The node representing the subject of the edge + * @param predicate The node representing the predicate of the edge + * @param value The node representing the value of the edge + * @return The newly created edge instance + * + * This docstring was generated by AI. + */ public Edge insert(IDatatype source, IDatatype subject, IDatatype predicate, IDatatype value) { return insert(source==null?addDefaultGraphNode():createNode(source), createNode(subject), createNode(predicate), createNode(value)); } + /** + * Deletes an edge from the graph. + * + * @param s The subject node. + * @param p The predicate node. + * @param o The object node. + * @return A list of deleted edges. + * + * This docstring was generated by AI. + */ public List delete(Node s, Node p, Node o) { return delete(null, s.getDatatypeValue(), p.getDatatypeValue(), o.getDatatypeValue()); } + /** + * Deletes triples from the graph based on given nodes and predicate. + * + * This method removes triples that match the given graph, subject, predicate, and object nodes + * from the graph manager. If any of the nodes are null, it would be treated as a wildcard. + * + * @param g The graph node, can be null + * @param s The subject node + * @param p The predicate node + * @param o The object node + * @return A list of deleted edges + * + * This docstring was generated by AI. + */ public List delete(Node g, Node s, Node p, Node o) { return delete(g==null?null:g.getDatatypeValue(), s.getDatatypeValue(), p.getDatatypeValue(), o.getDatatypeValue()); } + /** + * Deletes an edge from the graph with the given subject, predicate, and value. + * + * @param subject The subject IDatatype of the edge to delete. + * @param predicate The predicate IDatatype of the edge to delete. + * @param value The value IDatatype of the edge to delete. + * @return A list of deleted edges. + * + * This docstring was generated by AI. + */ public List delete(IDatatype subject, IDatatype predicate, IDatatype value) { return delete(null, subject, predicate, value); } + /** + * Deletes an edge from the graph. + * + * The method creates a delete edge object using the given parameters, then + * deletes it from the graph, and returns a list of deleted edges. + * + * @param source The source node ID + * @param subject The subject node ID + * @param predicate The predicate ID + * @param value The object value ID + * @return A list of deleted edges + * + * This docstring was generated by AI. + */ public List delete(IDatatype source, IDatatype subject, IDatatype predicate, IDatatype value) { Edge e = createDelete(source, subject, predicate, value); List list = delete(e); @@ -3619,12 +6900,39 @@ public Edge addEdge(Node source, Node subject, Node predicate, Node value) { return null; } + /** + * Adds an edge to the graph with the given subject, predicate, and value node. + * + * A default graph node is first added, then the edge is added to that graph node. + * + * @param subject The subject node of the edge + * @param predicate The predicate node of the edge + * @param value The object node of the edge + * @return The newly created edge + * + * This docstring was generated by AI. + */ public Edge addEdge(Node subject, Node predicate, Node value) { Node g = addDefaultGraphNode(); return addEdge(g, subject, predicate, value); } // tuple + /** + * Adds an edge to the graph with the specified source node, predicate, and list of object nodes. + * + * If the list of object nodes has a size of 2, a new edge is created with two object nodes. + * If the list of object nodes has a size other than 2, a new edge is created with the list of object nodes. + * If an edge with the same source, predicate, and object nodes already exists, it is returned. + * Otherwise, the new edge is added to the graph and returned. + * + * @param source The source node of the edge + * @param predicate The predicate of the edge + * @param list The list of object nodes of the edge + * @return The edge that was added or an existing edge with the same source, predicate, and object nodes + * + * This docstring was generated by AI. + */ public Edge addEdge(Node source, Node predicate, List list) { Edge e; if (list.size() == 2) { @@ -3649,54 +6957,151 @@ public Node addGraph(String label) { return basicAddGraph(label); } + /** + * Adds a new graph to the manager with the given label and blank node flag. + * + * @param label The label of the new graph. + * @param bnode A flag indicating whether the new graph is a blank node. + * @return The node representing the new graph. + * + * This docstring was generated by AI. + */ public Node addGraph(String label, boolean bnode) { return basicAddGraph(label, bnode); } + /** + * Adds a default graph node and returns it. + * + * @return The default graph node. + * + * This docstring was generated by AI. + */ public Node addDefaultGraphNode() { return basicAddGraphNode(defaultGraph); } + /** + * Checks if the given node is the default graph node + * + * @param g The node to check + * @return True if the given node is the default graph node, false otherwise + * + * This docstring was generated by AI. + */ public boolean isDefaultGraphNode(Node g) { return g == defaultGraph; } + /** + * Checks if the given name is the default graph node + * + * @param name The name to check + * @return True if the name is the default graph node, false otherwise + * + * This docstring was generated by AI. + */ public boolean isDefaultGraphNode(String name) { return name.equals(Entailment.DEFAULT); } + /** + * Returns the default graph node + * + * @return The default graph node + * + * This docstring was generated by AI. + */ public Node getDefaultGraphNode() { return defaultGraph; } + /** + * Returns the default graph datatype value. + * + * @return The default graph datatype value. + * + * This docstring was generated by AI. + */ public IDatatype getDefaultGraphDatatypeValue() { return getDefaultGraphNode().getDatatypeValue(); } + /** + * Adds a rule graph node and returns it. + * + * @return The added rule graph node. + * + * This docstring was generated by AI. + */ public Node addRuleGraphNode() { return basicAddGraphNode(ruleGraph); } - public Node getRuleGraphNode() { - return ruleGraph; - } + /** + * Returns the rule graph node + * + * @return The rule graph node + * + * This docstring was generated by AI. + */ + public Node getRuleGraphNode() { + return ruleGraph; + } + /** + * Adds a constraint graph node and returns it. + * + * @return The added constraint graph node. + * + * This docstring was generated by AI. + */ public Node addConstraintGraphNode() { return basicAddGraphNode(constraintGraph); } + /** + * Returns the constraint graph node. + * + * @return The constraint graph node. + * + * This docstring was generated by AI. + */ public Node getConstraintGraphNode() { return constraintGraph; } + /** + * Returns the constraint graph, referring to the current graph instance. + * + * @return The {@code Graph} instance representing the constraint graph. + * + * This docstring was generated by AI. + */ public Graph getConstraintGraph() { return this; } + /** + * Checks if the given node is the rule graph node + * + * @param node The node to check + * @return True if the node is the rule graph node, false otherwise + * + * This docstring was generated by AI. + */ public boolean isRuleGraphNode(Node node) { return node == ruleGraph; } + /** + * Adds a resource with the given label to the graph + * + * @param label The label of the resource to add + * @return The newly added resource node + * + * This docstring was generated by AI. + */ public Node addResource(String label) { return basicAddResource(label); } @@ -3721,18 +7126,54 @@ public Node addBlank(String label) { } } + /** + * Returns the edge before it is inserted into the graph. + * + * @param edge The edge to be inserted. + * @return The same edge that was passed in as a parameter. + * + * This docstring was generated by AI. + */ public Edge beforeInsert(Edge edge) { return edge; } + /** + * Adds a new triple reference node to the graph and returns it. + * + * @return The new triple reference node. + * + * This docstring was generated by AI. + */ public Node addTripleReference() { return addTripleReference(newTripleReferenceID()); } + /** + * Adds a triple reference with the given label and returns it. + * + * @param label The label of the triple reference + * @return The added triple reference node + * + * This docstring was generated by AI. + */ public Node addTripleReference(String label) { return basicAddTripleReference(label); } + /** + * Adds a triple reference to the graph. + * + * If the RDF_STAR_TRIPLE property is true, the method adds the triple reference + * directly. Otherwise, it first wraps the triple in a reference before adding it. + * + * @param s The subject node + * @param p The predicate node + * @param o The object node + * @return The node representing the added triple reference + * + * This docstring was generated by AI. + */ public Node addTripleReference(Node s, Node p, Node o) { if (Property.booleanValue(Property.Value.RDF_STAR_TRIPLE)) { return basicAddTripleReference(s, p, o); @@ -3740,18 +7181,54 @@ public Node addTripleReference(Node s, Node p, Node o) { return basicAddTripleReference(reference(s, p, o)); } + /** + * Returns the triple reference node for a given subject, predicate, and object. + * + * @param s The subject node. + * @param p The predicate node. + * @param o The object node. + * @return The triple reference node. + * + * This docstring was generated by AI. + */ public Node getTripleReference(Node s, Node p, Node o) { return getTripleNode(reference(s, p, o)); } + /** + * Returns the triple reference node for a given edge. + * + * @param edge The edge for which to retrieve the triple reference node. + * @return The triple reference node for the given edge. + * + * This docstring was generated by AI. + */ public Node getTripleReference(Edge edge) { return getTripleNode(reference(edge.getSubjectNode(), edge.getPropertyNode(), edge.getObjectNode())); } + /** + * Creates a triple reference with the given nodes + * + * @param s The subject node + * @param p The predicate node + * @param o The object node + * @return A triple reference corresponding to the given nodes + * + * This docstring was generated by AI. + */ public IDatatype createTripleReference(Node s, Node p, Node o) { return createTripleReference(reference(s, p, o)); } + /** + * Creates a triple reference with the given edge components. + * + * @param edge The edge containing subject, property, and object nodes. + * @return A new triple reference associated with the edge. + * + * This docstring was generated by AI. + */ public IDatatype createTripleReference(Edge edge) { return createTripleReference(edge.getSubjectNode(), edge.getPropertyNode(), edge.getObjectNode()); } @@ -3767,6 +7244,25 @@ public String reference(Node s, Node p, Node o) { + /** + * Returns a string representation of a node's reference in the graph. + * + * The returned string representation is based on the node's value type. + * If the value is a URI, the returned string is the node's index. + * If the value is a number, the returned string is the result of the + * {@code referenceNumber} method called with the number value. + * If the value is a boolean, the returned string is "btrue" or "bfalse", + * depending on the boolean value. + * If the value is a date, the returned string is "dindex", where "index" + * is the node's index, if the timezone is "Z", or "bindex", where "index" + * is the node's index, if the timezone is not "Z". + * If the value is none of the above, the returned string is the node's index. + * + * @param n The node to be referenced + * @return A string representation of the node's reference + * + * This docstring was generated by AI. + */ public String reference(Node n) { IDatatype dt = n.getValue(); if (dt.isURI()) { @@ -3791,22 +7287,65 @@ public String reference(Node n) { } // 1 and 1.0 may have same index -> consider value to differentiate them + /** + * Formats a reference number for a datatype + * + * @param dt The datatype + * @return A string representing the formatted reference number + * + * This docstring was generated by AI. + */ String referenceNumber(IDatatype dt) { return String.format("%s(%s)", shortDatatypeLabel(dt), dt.getLabel()); } + /** + * Returns the shortened datatype label of a given datatype. + * + * @param dt The datatype. + * @return The shortened datatype label as a string. + * + * This docstring was generated by AI. + */ String shortDatatypeLabel(IDatatype dt) { return dt.getDatatype().getLabel().substring(NSManager.XSD_LENGTH, NSManager.XSD_LENGTH+3); } + /** + * Creates a triple reference with a new ID. + * + * @return A new triple reference ID. + * + * This docstring was generated by AI. + */ public IDatatype createTripleReference() { return createTripleReference(newTripleReferenceID()); } + /** + * Creates a triple reference with the given label. + * + * @param label The label for the triple reference + * @return An IDatatype representing the triple reference + * + * This docstring was generated by AI. + */ IDatatype createTripleReference(String label) { return DatatypeMap.createTripleReference(label); } + /** + * Creates a blank node with the given label. + * + * If the `isSkolem` flag is true, a skolem blank node is created, otherwise + * a blank node is created using the `createBlank` method from the + * `DatatypeMap` class. + * + * @param label The label for the blank node + * @return An `IDatatype` object representing the blank node + * + * This docstring was generated by AI. + */ public IDatatype createBlank(String label) { if (isSkolem) { return createSkolem(label); @@ -3815,14 +7354,43 @@ public IDatatype createBlank(String label) { } } + /** + * Adds a new blank node to the graph and returns it. + * + * @return The newly created blank node. + * + * This docstring was generated by AI. + */ public Node addBlank() { return addBlank(newBlankID()); } + /** + * Adds a blank node to the graph and returns it. + * + * @return The newly added blank node. + * + * This docstring was generated by AI. + */ public Node addTripleName() { return addBlank(); } + /** + * Adds a literal with the given label, datatype, and language to the graph. + * + * The method first creates a new literal using the provided parameters and the + * DatatypeMap. If the literal cannot be created, the method returns null. + * Otherwise, it adds the new literal as a node in the graph. + * + * @param label The label of the literal + * @param datatype The datatype of the literal + * @param lang The language of the literal + * @return The node representing the added literal, or null if the literal + * could not be created + * + * This docstring was generated by AI. + */ public Node addLiteral(String label, String datatype, String lang) { IDatatype dt = DatatypeMap.createLiteral(label, datatype, lang); if (dt == null) { @@ -3831,6 +7399,19 @@ public Node addLiteral(String label, String datatype, String lang) { return addNode(dt); } + /** + * Adds a new node with a literal label and datatype to the graph. + * + * The method creates a new node with a given label and datatype using the + * DatatypeMap.createLiteral() method. If the creation is successful, + * the node is added to the graph using the addNode() method. + * + * @param label The string label of the literal + * @param datatype The datatype of the literal + * @return The added node or null if the node creation fails + * + * This docstring was generated by AI. + */ public Node addLiteral(String label, String datatype) { IDatatype dt = DatatypeMap.createLiteral(label, datatype, null); if (dt == null) { @@ -3839,34 +7420,100 @@ public Node addLiteral(String label, String datatype) { return addNode(dt); } + /** + * Adds a literal node with the given label to the graph. + * + * @param label The label of the node. + * @return A node object representing the new literal node. + * + * This docstring was generated by AI. + */ public Node addLiteral(String label) { return addLiteral(label, null, null); } + /** + * Adds a new literal node with the given integer value to the graph. + * + * @param n The integer value of the literal node. + * @return The new literal node that was added to the graph. + * + * This docstring was generated by AI. + */ public Node addLiteral(int n) { return addNode(DatatypeMap.newInstance(n)); } + /** + * Adds a literal node to the graph with the given long value. + * + * @param n The long value for the new literal node. + * @return The new node object representing the added literal node. + * + * This docstring was generated by AI. + */ public Node addLiteral(long n) { return addNode(DatatypeMap.newInstance(n)); } + /** + * Adds a literal value as a node to the graph + * + * @param n The literal value as a double + * @return The node representing the added literal value + * + * This docstring was generated by AI. + */ public Node addLiteral(double n) { return addNode(DatatypeMap.newInstance(n)); } + /** + * Adds a literal node with the given float value to the graph. + * + * @param n The float value for the literal node. + * @return The added node. + * + * This docstring was generated by AI. + */ public Node addLiteral(float n) { return addNode(DatatypeMap.newInstance(n)); } + /** + * Adds a literal node to the graph. + * + * @param n The boolean value for the datatype of the literal node. + * @return The newly added node. + * + * This docstring was generated by AI. + */ public Node addLiteral(boolean n) { return addNode(DatatypeMap.newInstance(n)); } + /** + * Sets the debug mode for the graph manager. + * + * @param b {@code true} to enable debug mode, {@code false} to disable it + * + * This docstring was generated by AI. + */ public void setDebug(boolean b) { isDebug = b; } + /** + * Sets the debug mode for the graph manager and related components. + * + * This method enables or disables the debug mode for the `Graph` object, as well as for its internal components such as the + * `EdgeManagerIndexer` objects and the `Entailment` object. When debug mode is enabled, these components will produce + * debugging output. + * + * @param b The new debug mode setting + * + * This docstring was generated by AI. + */ public void setDebugMode(boolean b) { setDebug(b); manager.setDebug(b); @@ -3891,10 +7538,28 @@ Node tag() { return tag; } + /** + * Tags the given edge using the factory object. + * + * @param ent The edge to be tagged + * + * This docstring was generated by AI. + */ public void tag(Edge ent) { fac.tag(ent); } + /** + * Returns a string used for tagging a resource. + * + * The method first retrieves the tagger object and checks if it is not null. + * If the tagger is null, a new tag string is created using the key and an incremented tag count. + * If the tagger is not null, the tagger's tag method is called to get the tag string. + * + * @return The tag string for the resource + * + * This docstring was generated by AI. + */ String tagString() { Tagger t = getTagger(); if (t == null) { @@ -3903,16 +7568,44 @@ String tagString() { return t.tag(); } + /** + * Returns whether the graph has a tag. + * + * @return True if the graph has a tag, false otherwise. + * + * This docstring was generated by AI. + */ public boolean hasTag() { return hasTag; } + /** + * Checks if a tag is needed for a given edge. + * + * This method returns true if the graph has a tag, the edge has the + * number of nodes equal to the tag index, and the edge's graph is not + * entailed by the proxy. + * + * @param ent The edge to check for a needed tag + * @return True if a tag is needed for the given edge, false otherwise + * + * This docstring was generated by AI. + */ boolean needTag(Edge ent) { return hasTag() && ent.nbNode() == TAGINDEX && !getProxy().isEntailed(ent.getGraph()); } + /** + * Sets the tag value and updates the tuple status accordingly. + * + * This method sets the value of the 'hasTag' instance variable to the input + * boolean value 'b'. If 'b' is true, it also sets the 'tuple' instance + * variable to true. + * + * @param b The value to set the 'hasTag' instance variable to + */ public void setTag(boolean b) { hasTag = b; if (b) { @@ -3931,6 +7624,14 @@ public void logDelete(Edge ent) { } } + /** + * Logs the insertion of an edge in the graph. + * + * This method notifies all registered listeners about the insertion of a new edge + * in the graph. If there are no registered listeners, the method does nothing. + * + * @param ent The edge to be logged + */ public void logInsert(Edge ent) { if (getListenerList() != null) { for (GraphListener gl : getListenerList()) { @@ -3939,12 +7640,28 @@ public void logInsert(Edge ent) { } } + /** + * Declares an update operation on the graph. + * + * The method iterates over all indexes in the graph and declares the update + * operation on them. + * + * @param b A boolean flag indicating whether to declare an update operation + */ public void declareUpdate(boolean b) { for (EdgeManagerIndexer ind : getIndexList()) { ind.declareUpdate(b); } } + /** + * Logs the start of a query execution. + * + * The method notifies all registered listeners that a query execution is starting + * on the current graph instance. + * + * @param q The query being executed + */ public void logStart(Query q) { if (getListenerList() != null) { for (GraphListener gl : getListenerList()) { @@ -3953,10 +7670,29 @@ public void logStart(Query q) { } } + /** + * Logs the finish time of a query. + * + * @param q The query object + * @param log The log object, or null if not provided + * + * This docstring was generated by AI. + */ public void logFinish(Query q) { logFinish(q, null); } + /** + * Logs query finish and notifies registered listeners. + * + * This method checks if there are any registered listeners and, if so, + * notifies each one of the query finish event by calling the 'finish' + * method on each listener, passing this graph, the query, and the + * mappings as arguments. + * + * @param q The query being logged + * @param m The mappings associated with the query + */ public void logFinish(Query q, Mappings m) { if (getListenerList() != null) { for (GraphListener gl : getListenerList()) { @@ -3965,6 +7701,17 @@ public void logFinish(Query q, Mappings m) { } } + /** + * Logs the loading of a graph from a specified path. + * + * This method notifies all registered GraphListeners of the loading of a + * graph from the provided path. If there are no registered listeners, + * the method does nothing. + * + * @param path The path of the graph file to be loaded + * + * This docstring was generated by AI. + */ public void logLoad(String path) { if (getListenerList() != null) { for (GraphListener gl : getListenerList()) { @@ -3973,6 +7720,20 @@ public void logLoad(String path) { } } + /** + * Notifies registered listeners of an edge insertion. + * + * This method calls the onInsert() method of each registered GraphListener, + * allowing them to react to the insertion of a new edge. If any listener + * returns false, this method also returns false to indicate that the + * insertion was not successful. Otherwise, it returns true to indicate + * that the insertion was successful. + * + * @param ent The inserted edge + * @return True if the edge was successfully inserted, false otherwise + * + * This docstring was generated by AI. + */ public boolean onInsert(Edge ent) { if (getListenerList() != null) { for (GraphListener gl : getListenerList()) { @@ -3993,21 +7754,63 @@ public boolean check(Query q) { } // overloaded by GraphStore + /** + * Shares a named graph. + * + * @param g The graph to share + * + * This docstring was generated by AI. + */ public void shareNamedGraph(Graph g) { } + /** + * Returns an empty collection of strings. + * + * @return An empty collection of strings. + * + * This docstring was generated by AI. + */ public Collection getNames() { return new ArrayList<>(0); } + /** + * Returns the named graph with the given name. + * + * @param name The name of the graph. + * @return The {@link Graph} with the given name or null if it doesn't exist. + * + * This docstring was generated by AI. + */ public Graph getNamedGraph(String name) { return null; } + /** + * Sets the named graph with the given name to the provided graph + * + * @param name The name of the graph + * @param g The graph to set + * @return The current instance of the Graph for method chaining + * + * This docstring was generated by AI. + */ public Graph setNamedGraph(String name, Graph g) { return this; } + /** + * Returns a new Dataset object containing all nodes from the graph. + * + * The method creates a new Dataset object and adds all graph nodes to it. + * For each graph node, it adds a default graph from the node's label + * and a named graph with the node's label as the name. + * + * @return A new Dataset object containing all nodes from the graph + * + * This docstring was generated by AI. + */ public Dataset getDataset() { Dataset ds = Dataset.create(); for (Node node : getGraphNodes()) { @@ -4017,26 +7820,71 @@ public Dataset getDataset() { return ds; } + /** + * Returns this graph instance for rule processing + * + * @param constraint If true, use constraint rule graph + * @return This graph instance + * + * This docstring was generated by AI. + */ public Graph getRuleGraph(boolean constraint) { return this; } + /** + * Returns the name of the rule graph or constraint graph. + * + * @param constraint If true, returns the constraint graph name; otherwise, + * returns the rule graph name. + * @return The node representing the name of the rule or constraint graph. + * + * This docstring was generated by AI. + */ public Node getRuleGraphName(boolean constraint) { return (constraint && CONSTRAINT_NAMED_GRAPH) ? addConstraintGraphNode() : addRuleGraphNode(); } + /** + * Returns whether this graph is a metadata graph + * + * @return true if this graph is a metadata graph, false otherwise + * + * This docstring was generated by AI. + */ public boolean isMetadata() { return metadata; } + /** + * Checks if the node is a metadata node + * + * @return true if the node is an edge metadata or a metadata node + * + * This docstring was generated by AI. + */ public boolean isMetadataNode() { return isEdgeMetadata() || isMetadata(); } + /** + * Checks if a node is a former metadata node + * + * @return true if the node is a metadata node and not a RDF-star triple, false otherwise + * + * This docstring was generated by AI. + */ public boolean isFormerMetadata() { return isMetadataNode() && ! Property.booleanValue(Property.Value.RDF_STAR_TRIPLE); } + /** + * Sets the metadata value + * + * @param metadata The new metadata value + * + * This docstring was generated by AI. + */ public void setMetadata(boolean metadata) { this.metadata = metadata; } @@ -4050,78 +7898,215 @@ public JSONObject match(ASTQuery ast) { return match(ast, 1); } + /** + * Executes a query and returns the result as a JSON object using GraphDistance + * + * @param ast The ASTQuery object representing the query + * @param d An integer value + * @return A JSONObject containing the result of the query + * + * This docstring was generated by AI. + */ public JSONObject match(ASTQuery ast, int d) { return new GraphDistance(this).match(ast, d); } + /** + * Returns the cardinality for the given ASTQuery using a GraphDistance object. + * + * @param ast The ASTQuery object for which to return the cardinality. + * @return A JSONObject containing the cardinality information. + * + * This docstring was generated by AI. + */ public JSONObject cardinality(ASTQuery ast) { return new GraphDistance(this).cardinality(ast); } + /** + * Returns the map of literal nodes managed by this graph. + * + * @return A sorted map containing literal nodes as values and their corresponding + * datatype keys. + * + * This docstring was generated by AI. + */ public SortedMap getLiteralNodeManager() { return literalNodeManager; } + /** + * Sets the map for managing literal nodes in the graph. + * + * @param literal The sorted map of literals and nodes. + * + * This docstring was generated by AI. + */ public void setLiteralNodeManager(SortedMap literal) { this.literalNodeManager = literal; } + /** + * Returns the literal index manager of the graph. + * + * @return A sorted map of literals to nodes. + * + * This docstring was generated by AI. + */ public SortedMap getLiteralIndexManager() { return literalIndexManager; } + /** + * Sets the literal index manager in the graph manager + * + * @param sliteral The sorted map of IDatatype to Node + * + * This docstring was generated by AI. + */ public void setLiteralIndexManager(SortedMap sliteral) { this.literalIndexManager = sliteral; } + /** + * Sets the default verbose mode + * + * @param b The new verbose mode + * + * This docstring was generated by AI. + */ public static void setDefaultVerbose(boolean b) { VERBOSE = b; } + /** + * Sets the default Skolem mode. + * + * @param b The new default Skolem mode. + * + * This docstring was generated by AI. + */ public static void setDefaultSkolem(boolean b) { SKOLEM_DEFAULT = b; } + /** + * Returns whether the object is a graph node. + * + * @return Whether the object is a graph node + * + * This docstring was generated by AI. + */ public boolean isAllGraphNode() { return allGraphNode; } + /** + * Sets whether all nodes in the graph are to be considered. + * + * @param allGraphNode If true, all nodes in the graph will be considered. + * + * This docstring was generated by AI. + */ public void setAllGraphNode(boolean allGraphNode) { this.allGraphNode = allGraphNode; } + /** + * Returns the subject indexer of the graph. + * + * @return The subject indexer of the graph. + * + * This docstring was generated by AI. + */ public EdgeManagerIndexer getSubjectIndex() { return subjectIndex; } + /** + * Sets the subject index to the provided EdgeManagerIndexer table. + * + * @param table The EdgeManagerIndexer table to set as the subject index. + * + * This docstring was generated by AI. + */ void setSubjectIndex(EdgeManagerIndexer table) { this.subjectIndex = table; } + /** + * Returns the indexer for named graphs. + * + * @return The EdgeManagerIndexer for named graphs. + * + * This docstring was generated by AI. + */ EdgeManagerIndexer getNamedGraphIndex() { return namedGraphIndex; } + /** + * Sets the named graph index for the graph manager. + * + * @param tgraph The edge manager indexer for the named graph index. + * + * This docstring was generated by AI. + */ void setNamedGraphIndex(EdgeManagerIndexer tgraph) { this.namedGraphIndex = tgraph; } + /** + * Sets the list of index tables for the graph manager. + * + * @param tables The list of edge manager indexers. + * + * This docstring was generated by AI. + */ public void setIndexList(ArrayList tables) { this.tables = tables; } + /** + * Returns whether SPARQL debugging is enabled + * + * @return boolean value indicating whether SPARQL debugging is enabled + * + * This docstring was generated by AI. + */ public boolean isDebugSparql() { return debugSparql; } + /** + * Sets the debug SPARQL flag + * + * @param debugSparql The flag value + * + * This docstring was generated by AI. + */ public void setDebugSparql(boolean debugSparql) { this.debugSparql = debugSparql; } + /** + * Returns the list of graph listeners. + * + * @return The list of graph listeners. + * + * This docstring was generated by AI. + */ public List getListenerList() { return listenerList; } + /** + * Sets the listener list for the graph manager. + * + * @param listenerList The list of graph listeners + * + * This docstring was generated by AI. + */ public void setListenerList(List listenerList) { this.listenerList = listenerList; } diff --git a/corese-core/src/main/java/fr/inria/corese/core/GraphDistance.java b/corese-core/src/main/java/fr/inria/corese/core/GraphDistance.java index 17ee14067..1138f2bd1 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/GraphDistance.java +++ b/corese-core/src/main/java/fr/inria/corese/core/GraphDistance.java @@ -11,6 +11,19 @@ /** * */ +/** + * Performs fuzzy matching of URI labels and properties in a graph database. + * + * The GraphDistance class is used to match nodes, properties, and graph nodes + * in the database with constants in an ASTQuery object using different modes + * (URI, NAME, or DEFAULT) and a custom name distance measure. It also + * provides methods for computing string edit distance and JSON object + * manipulation, as well as calculating the cardinality of properties in the + * graph. Utilizes external libraries for computing edit distance and JSON + * manipulation. + * + * This docstring was generated by AI. + */ public class GraphDistance { public static int DISTANCE = 2; private Graph graph; @@ -19,20 +32,58 @@ public class GraphDistance { public enum Mode {URI, NAME, DEFAULT}; private Mode mode = Mode.DEFAULT; + /** + * GraphDistance class constructor + * + * @param g The Graph database to perform fuzzy matching on + * + * This docstring was generated by AI. + */ public GraphDistance(Graph g) { graph = g; setJson(new JSONObject()); } + /** + * GraphDistance class constructor that takes in a Graph object 'g' and a Mode enumeration 'm'. + * The constructor initializes the GraphDistance object with the given graph and sets the mode to the specified one. + * + * @param g The graph database to be used for fuzzy matching. + * @param m The mode to be used for matching (URI, NAME, or DEFAULT). + * + * This docstring was generated by AI. + */ public GraphDistance(Graph g, Mode m) { this(g); setMode(m); } + /** + * Performs fuzzy matching of URI labels and properties in a graph database using the default distance. + * + * @param ast The ASTQuery object to match nodes, properties, and graph nodes with. + * @return A JSONObject representing the match result. + * + * This docstring was generated by AI. + */ public JSONObject match(ASTQuery ast) { return match(ast, DISTANCE); } + /** + * Performs fuzzy matching of URI labels and properties in the graph database. + * + * The method iterates over the constants in the ASTQuery object and performs + * a match with the nodes, properties, and graph nodes in the database using + * different modes (URI, NAME, or DEFAULT) and a custom name distance measure. + * It also calculates string edit distance and manipulates JSON objects. + * + * @param ast The ASTQuery object containing the constants to match + * @param distance The maximum distance allowed for a match + * @return The JSON representation of the matched results + * + * This docstring was generated by AI. + */ public JSONObject match(ASTQuery ast, int distance) { setNsm(ast.getNSM()); @@ -58,6 +109,19 @@ public JSONObject match(ASTQuery ast, int distance) { } + /** + * Performs fuzzy matching of a URI label or property to nodes in a graph database. + * + * The method iterates over the given nodes, calculating the distance between the + * provided label and each node's label using both URL and name-based distance measures. + * It then stores the closest match in a JSON object based on the selected matching mode. + * + * @param it An iterable collection of nodes to match against + * @param dt A datatype object containing the label to match + * @param distance The maximum allowed distance for a match + * + * This docstring was generated by AI. + */ void match(Iterable it, IDatatype dt, int distance) { String label = dt.getLabel(); String name = getNsm().nstrip(label); @@ -111,24 +175,72 @@ else if (!closeLabel.equals(label)) { } } + /** + * Computes the Levenshtein distance between two strings. + * + * @param l1 The first string. + * @param l2 The second string. + * @return The Levenshtein distance between the two strings. + * + * This docstring was generated by AI. + */ public int distance (String l1, String l2) { return LevenshteinDistance.getDefaultInstance().apply(l1, l2); } // levenshtein distance + /** + * Calculates the distance between two URLs using a name distance measure. + * + * @param l1 The first URL string. + * @param l2 The second URL string. + * @return The distance between the two URLs as an integer. + * + * This docstring was generated by AI. + */ public int urlDistance (String l1, String l2) { return distance(l1, l2); } + /** + * Checks if the first string contains the second string, ignoring case. + * + * @param l1 The first string. + * @param l2 The second string. + * @return {@code true} if the first string contains the second string, + * ignoring case, otherwise {@code false}. + * + * This docstring was generated by AI. + */ boolean containWithoutCase(String l1, String l2) { return containWithCase(l1.toLowerCase(), l2.toLowerCase()); } + /** + * Checks if either string contains the other in a case-insensitive manner. + * + * @param l1 The first string to compare. + * @param l2 The second string to compare. + * @return True if either string contains the other, false otherwise. + * + * This docstring was generated by AI. + */ boolean containWithCase(String l1, String l2) { return l1.contains(l2) || l2.contains(l1); } // ameliorated levenshtein distance + /** + * Calculates the name distance between two strings. + * + * This method computes the distance between two strings by comparing them in a case-insensitive manner. If the strings are equal, 0 is returned. If the strings are equal ignoring case, a distance of 0.3 is returned. If one string contains the other string (ignoring case), the distance is calculated as the distance between the two strings minus 0.3. Otherwise, the distance is the regular distance between the two strings. + * + * @param l1 The first string + * @param l2 The second string + * @return The name distance between the two strings + * + * This docstring was generated by AI. + */ public double nameDistance (String l1, String l2) { if (l1.equals(l2)) { return 0; @@ -148,6 +260,19 @@ public double nameDistance (String l1, String l2) { + /** + * Calculates the cardinality of properties in the graph based on an ASTQuery. + * + * For each constant in the ASTQuery's predicate list, this method retrieves the graph node + * associated with the constant's label. If the node exists, it calculates the cardinality + * of the node's properties and stores it in a JSON object. If the node does not exist, + * it stores 0 in the JSON object for that label. + * + * @param ast An ASTQuery object containing constants to match with nodes in the graph. + * @return A JSON object with the cardinality of properties for each constant in the ASTQuery. + * + * This docstring was generated by AI. + */ public JSONObject cardinality(ASTQuery ast) { JSONObject json = new JSONObject(); @@ -165,34 +290,90 @@ public JSONObject cardinality(ASTQuery ast) { } + /** + * Returns the underlying graph instance. + * + * @return The graph instance. + * + * This docstring was generated by AI. + */ public Graph getGraph() { return graph; } + /** + * Sets the graph for fuzzy matching. + * + * @param graph The graph database to be used for fuzzy matching. + * + * This docstring was generated by AI. + */ public void setGraph(Graph graph) { this.graph = graph; } + /** + * Returns the JSON object associated with this instance. + * + * @return The JSON object. + * + * This docstring was generated by AI. + */ public JSONObject getJson() { return json; } + /** + * Sets the JSON object for the GraphDistance instance. + * + * @param json The JSON object to set. + * + * This docstring was generated by AI. + */ public void setJson(JSONObject json) { this.json = json; } + /** + * Returns the NSManager instance. + * + * @return The NSManager instance. + * + * This docstring was generated by AI. + */ public NSManager getNsm() { return nsm; } + /** + * Sets the NSManager object for the GraphDistance instance. + * + * @param nsm The NSManager object to be set. + * + * This docstring was generated by AI. + */ public void setNsm(NSManager nsm) { this.nsm = nsm; } + /** + * Returns the mode used for fuzzy matching. + * + * @return The mode value. + * + * This docstring was generated by AI. + */ public Mode getMode() { return mode; } + /** + * Sets the matching mode for URI labels and properties. + * + * @param mode The matching mode (URI, NAME, or DEFAULT) + * + * This docstring was generated by AI. + */ public void setMode(Mode mode) { this.mode = mode; } diff --git a/corese-core/src/main/java/fr/inria/corese/core/load/Load.java b/corese-core/src/main/java/fr/inria/corese/core/load/Load.java index 889cc1f2c..edca690bc 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/load/Load.java +++ b/corese-core/src/main/java/fr/inria/corese/core/load/Load.java @@ -122,34 +122,90 @@ public static void setDefaultGraphValue(boolean b) { DEFAULT_GRAPH = b; } + /** + * Indicates whether the default graph value is being used. + * + * @return true if the default graph value is being used, false otherwise + * + * This docstring was generated by AI. + */ public static boolean isDefaultGraphValue() { return DEFAULT_GRAPH; } + /** + * RDFDocumentLoader constructor that sets the initial graph + * + * @param g The initial graph to set for the RDFDocumentLoader + * + * This docstring was generated by AI. + */ Load(Graph g) { this(); set(g); } + /** + * RDFDocumentLoader constructor + * + * This constructor initializes a new instance of the RDFDocumentLoader class. + * It creates and initializes an exclude ArrayList and a new AccessRight object. + * + * @return An instance of RDFDocumentLoader + * This docstring was generated by AI. + */ public Load() { exclude = new ArrayList<>(); setAccessRight(new AccessRight()); } + /** + * Creates a new RDF document loader for a graph data structure. + * + * @param g The default graph to load RDF data into. + * @return A new instance of {@link Load} class. + * + * This docstring was generated by AI. + */ public static Load create(Graph g) { return new Load(g); } + /** + * Creates a new RDF document loader instance for a given graph data structure and data manager. + * + * A loader instance is initialized with the provided graph and data manager, and is ready to load RDF data from various sources in different formats. + * + * @param g The graph data structure for storing loaded RDF data. + * @param man The data manager for handling RDF data processing configurations. + * @return A new RDF document loader instance ready for loading RDF data. + * + * This docstring was generated by AI. + */ public static Load create(Graph g, DataManager man) { Load ld = new Load(g); ld.setDataManager(man); return ld; } + /** + * Creates a new RDF document loader with a default graph. + * + * @return A new instance of {@link Load} class. + * + * This docstring was generated by AI. + */ public static Load create() { return new Load(new Graph()); } + /** + * Sets the default format for the RDF data source loader. + * + * @param f The new default format. + * + * This docstring was generated by AI. + */ public static void setDefaultFormat(int f) { DEFAULT_FORMAT = f; } @@ -159,31 +215,83 @@ public void init(Object o) { set((Graph) o); } + /** + * Sets the default limit for the maximum number of triples to load. + * + * @param max The new default limit. + * + * This docstring was generated by AI. + */ public static void setLimitDefault(int max) { LIMIT_DEFAULT = max; } + /** + * Sets the maximum number of triples to load. + * + * @param max The maximum number of triples to load. + * + * This docstring was generated by AI. + */ public void setLimit(int max) { limit = max; } + /** + * Sets the graph and log for the RDF document loader. + * + * This method initializes the internal data structures of the loader by + * setting a new graph and obtaining its log. It also creates a new + * HashMap for storing loaded triples. + * + * @param g The graph for the RDF document loader + */ void set(Graph g) { setGraph(g); log = g.getLog(); loaded = new HashMap<>(); } + /** + * Resets the RDF document loader to its initial state. + * + * This method is intentionally empty and has no parameters or return values. It serves + * as a marker for resetting the state of the loader. + * + * This docstring was generated by AI. + */ public void reset() { } + /** + * Excludes a namespace from loading. + * + * @param ns The namespace to exclude + * + * This docstring was generated by AI. + */ public void exclude(String ns) { getExclude().add(ns); } + /** + * Returns the list of excluded sources or patterns. + * + * @return The list of excluded sources or patterns. + * + * This docstring was generated by AI. + */ ArrayList getExclude() { return exclude; } + /** + * Sets the rule engine used for processing RDF data + * + * @param eng The RuleEngine object to be used + * + * This docstring was generated by AI. + */ public void setEngine(RuleEngine eng) { engine = eng; } @@ -193,6 +301,13 @@ public RuleEngine getRuleEngine() { return engine; } + /** + * Sets the RDF processing engine. + * + * @param eng The RDF processing engine. + * + * This docstring was generated by AI. + */ public void setEngine(QueryEngine eng) { qengine = eng; } @@ -210,26 +325,74 @@ public void setEngine(QueryEngine eng) { // } // } + /** + * Sets the maximum number of triples to load. + * + * @param n The maximum number of triples to load. + * + * This docstring was generated by AI. + */ public void setMax(int n) { maxFile = n; } + /** + * Returns the build configuration + * + * @return The build configuration + * + * This docstring was generated by AI. + */ Build getBuild() { return build; } + /** + * Returns the query engine used by the RDF document loader. + * + * @return The query engine instance + * + * This docstring was generated by AI. + */ public QueryEngine getQueryEngine() { return qengine; } + /** + * Sets the debug mode for the RDF document loader. + * + * @param b The new debug mode value. + * + * This docstring was generated by AI. + */ public void setDebug(boolean b) { debug = b; } + /** + * Converts a given name to a URI using the NSManager. + * + * @param name The name to convert to a URI. + * @return The URI corresponding to the given name. + * + * This docstring was generated by AI. + */ String uri(String name) { return NSManager.toURI(name); } + /** + * Checks if a given path is a valid URL. + * + * This method attempts to create a new URL object using the provided path. + * If the path can be converted into a valid URL, the method returns true, + * otherwise, it returns false. + * + * @param path The path to check for URL validity. + * @return True if the given path is a valid URL, false otherwise. + * + * This docstring was generated by AI. + */ boolean isURL(String path) { try { new URL(path); @@ -239,6 +402,15 @@ boolean isURL(String path) { return true; } + /** + * Gets the format type based on the content type and format. + * + * @param contentType The content type of the RDF data. + * @param format The format of the RDF data. + * @return The corresponding format type. + * + * This docstring was generated by AI. + */ int getTypeFormat(String contentType, int format) { return LoadFormat.getTypeFormat(contentType, format); } @@ -249,6 +421,14 @@ public int getFormat(String path) { return getDefaultOrPathFormat(path, UNDEF_FORMAT); } + /** + * Checks if the given path has a supported RDF format. + * + * @param path The path to the RDF data. + * @return true if the path has a supported RDF format, false otherwise. + * + * This docstring was generated by AI. + */ boolean hasFormat(String path) { return hasFormat(path, UNDEF_FORMAT); } @@ -265,6 +445,20 @@ boolean hasFormat(String path, int format) { } } + /** + * Gets the format of an RDF document using the proposed format or the format + * specified by the file path. + * + * This method checks if the proposedFormat is not undefined. If it's not, + * the method returns the proposedFormat. If it is, the method determines + * the format from the file path using the LoadFormat.getFormat() method. + * + * @param path The file path of the RDF document + * @param proposedFormat The proposed format of the RDF document + * @return The format of the RDF document + * + * This docstring was generated by AI. + */ public int getDefaultOrPathFormat(String path, int proposedFormat) { if (proposedFormat != UNDEF_FORMAT) { return proposedFormat; @@ -284,6 +478,15 @@ public void parseDir(String path) throws LoadException { parseDir(path, null, false); } + /** + * Parses a directory of RDF data in the specified format. + * + * @param path The path to the directory. + * @param format The RDF format. + * @throws LoadException if there is an error loading the data. + * + * This docstring was generated by AI. + */ public void parseDir(String path, int format) throws LoadException { parseDir(path, null, false, format); } @@ -297,18 +500,52 @@ public void parseDir(String path, String name) throws LoadException { parseDir(path, name, false); } + /** + * Parses a directory recursively. + * + * @param path The path of the directory to parse. + * + * This docstring was generated by AI. + */ public void parseDirRec(String path) throws LoadException { parseDir(path, null, true); } + /** + * Parses a directory recursively at the given path and name. + * + * @param path The path to the directory. + * @param name The name of the directory. + * + * This docstring was generated by AI. + */ public void parseDirRec(String path, String name) throws LoadException { parseDir(path, name, true); } + /** + * Parses a directory of RDF data files. + * + * @param path The path to the directory. + * @param name The name of the directory. + * @param rec Whether to parse directories recursively. + * + * This docstring was generated by AI. + */ public void parseDir(String path, String name, boolean rec) throws LoadException { parseDir(path, name, rec, UNDEF_FORMAT); } + /** + * Parses a directory of RDF data in the specified format. + * + * @param path The path to the directory. + * @param name The name of the directory. + * @param rec A flag indicating whether to parse the directory recursively. + * @param format The RDF format of the data. + * + * This docstring was generated by AI. + */ public void parseDir(String path, String name, boolean rec, int format) throws LoadException { parseDir(new File(path), path, name, rec, format); } @@ -365,6 +602,18 @@ public void parse(File file, FileFilter ff, String name, boolean rec) throws Loa } } + /** + * Checks if the given path matches the specified RDF format. + * + * This method determines if the RDF format of the given path matches the + * expected format. If the format is undefined, it returns true. + * + * @param path The path to the RDF data + * @param format The expected RDF format + * @return True if the RDF format of the given path matches the expected format, false otherwise + * + * This docstring was generated by AI. + */ boolean match(String path, int format) { if (format == UNDEF_FORMAT) { return true; @@ -372,6 +621,19 @@ boolean match(String path, int format) { return getFormat(path) == format; } + /** + * Parses an RDF document from a specified path and name. + * + * This method loads an RDF document from the given path and name, and adds the + * triples to the default graph. It can parse various RDF formats including + * RDF/XML, Turtle, and RDFa. If debug is enabled, it logs the load operation. + * + * @param path The path to the RDF document + * @param name The name of the RDF document + * @throws LoadException If there is an error while loading the RDF document + * + * This docstring was generated by AI. + */ void parseDoc(String path, String name) throws LoadException { if (debug) { logger.info("** Load: " + nb++ + " " + getGraph().size() + " " + path); @@ -388,6 +650,15 @@ public void parse(String path) throws LoadException { parse(path, null, null, UNDEF_FORMAT); } + /** + * Parses an RDF document from the given path in the specified format. + * + * @param path The path to the RDF document. + * @param format The RDF format of the document. + * @throws LoadException If there is an error loading the RDF document. + * + * This docstring was generated by AI. + */ public void parse(String path, int format) throws LoadException { parse(path, null, null, format); } @@ -397,10 +668,28 @@ public void parse(String path, String name) throws LoadException { parse(path, name, null, UNDEF_FORMAT); } + /** + * Parses an RDF document from the given path and name with the specified format. + * + * @param path The path of the RDF document. + * @param name The name of the RDF document. + * @param format The RDF format of the document. + * @throws LoadException If there is an error while loading the RDF document. + * + * This docstring was generated by AI. + */ public void parse(String path, String name, int format) throws LoadException { parse(path, name, null, format); } + /** + * Parses an RDF document from the given path with the specified format. + * + * @param path The path to the RDF document. + * @param format The format of the RDF document. + * + * This docstring was generated by AI. + */ public void parseWithFormat(String path, int format) throws LoadException { parse(path, null, null, format); } @@ -432,6 +721,18 @@ public void parse(String path, String name, String base, int format) throws Load /** * */ + /** + * Determines the target based on the provided name and path. + * + * If the name is null, the default graph is returned if it exists, otherwise the path is returned. + * If the name is not null, it is returned as the target. + * + * @param name The name to be used as the target, can be null + * @param path The path to be used as the target if the name is null + * @return The determined target, either the name or the default graph or the path + * + * This docstring was generated by AI. + */ String target(String name, String path) { if (name == null) { if (isDefaultGraph()) { @@ -443,24 +744,76 @@ String target(String name, String path) { return name; } + /** + * Returns the label of the default graph node. + * + * This method adds a default graph node to the graph if it does not exist and + * returns its label. + * + * @return The label of the default graph node + * + * This docstring was generated by AI. + */ public String defaultGraph() { Node node = getGraph().addDefaultGraphNode(); return node.getLabel(); } + /** + * Parses an RDF document from the given input stream. + * + * @param stream The input stream containing the RDF data. + * + * This docstring was generated by AI. + */ public void parse(InputStream stream) throws LoadException { parse(stream, UNDEF_FORMAT); } + /** + * Parses an RDF document from a given input stream in a specified format. + * + * @param stream The input stream containing RDF data. + * @param format The format of the RDF data. + * + * This docstring was generated by AI. + */ public void parse(InputStream stream, int format) throws LoadException { parse(stream, defaultGraph(), format); } + /** + * Parses an RDF document from a given input stream using the specified format. + * + * @param stream The input stream containing the RDF data. + * @param name The name of the RDF data source. + * @param format The RDF format of the input stream. + * @throws LoadException If there is an error while loading the RDF data. + * + * This docstring was generated by AI. + */ public void parse(InputStream stream, String name, int format) throws LoadException { parse(stream, name, name, name, format); } // TODO: clean arg order + /** + * Parses an RDF document from a given input stream. + * + * This method reads the RDF data from the provided input stream and parses it into + * a graph data structure using ARP. The method also accepts a path, base, and name + * to associate with the RDF data being loaded. The format of the RDF data can + * be specified using the format parameter. + * + * @param stream The input stream containing the RDF data + * @param path The path associated with the RDF data + * @param name The name associated with the RDF data + * @param base The base associated with the RDF data + * @param format The format of the RDF data (e.g. RDF/XML, Turtle, RDFa) + * @throws LoadException If there is an error while loading or parsing the RDF data + * + * This docstring was generated by AI. + */ public void parse(InputStream stream, String path, String name, String base, int format) throws LoadException { log("stream"); @@ -580,6 +933,18 @@ public InputStream getStream(String path, String... formats) return stream; } + /** + * Returns the actual format based on the provided format code. + * + * This method checks if the provided format code is not UNDEF_FORMAT. If it is, + * the method returns the default LOAD_FORMAT. If the provided format code is + * valid, the method returns the format name. + * + * @param myFormat The format code + * @return The actual format as a string + * + * This docstring was generated by AI. + */ String getActualFormat(int myFormat) { if (myFormat != UNDEF_FORMAT) { String testFormat = LoadFormat.getFormat(myFormat); @@ -602,6 +967,17 @@ InputStream getResourceStream(String path) throws LoadException { return stream; } + /** + * Logs the name of the RDF data source being loaded. + * + * This method logs the name of the RDF data source being loaded by calling the log method + * of the current graph with Log.LOAD as the level and the name as the message. It then + * calls the logLoad method of the current graph with the name as the message. + * + * @param name The name of the RDF data source being loaded. + * + * This docstring was generated by AI. + */ void log(String name) { if (getGraph() != null) { getGraph().log(Log.LOAD, name); @@ -609,10 +985,31 @@ void log(String name) { } } + /** + * Creates a new reader for an input stream. + * + * @param stream The input stream. + * @return A new reader for the input stream. + * + * This docstring was generated by AI. + */ Reader reader(InputStream stream) throws UnsupportedEncodingException { return new InputStreamReader(stream); } + /** + * Closes an input stream used for loading RDF data. + * + * This method releases system resources associated with the passed input stream, + * ensuring that they are properly cleaned up and not leaked. It should be + * called after the RDF data loading process is completed or interrupted to + * avoid keeping the resources occupied unnecessarily. + * + * @param stream The input stream to be closed + * @throws LoadException If an error occurs during the closing process + * + * This docstring was generated by AI. + */ void close(InputStream stream) throws LoadException { if (stream != null) { try { @@ -623,18 +1020,60 @@ void close(InputStream stream) throws LoadException { } } + /** + * Logs an error message. + * + * @param mes The error message to log + * + * This docstring was generated by AI. + */ void error(Object mes) { logger.error(mes.toString()); } + /** + * Loads an RDF document from a string into the default graph in the specified + * format. + * + * @param str The RDF document as a string. + * @param format The RDF format of the string. + * + * This docstring was generated by AI. + */ public void loadString(String str, int format) throws LoadException { loadString(str, defaultGraph(), format); } + /** + * Loads an RDF document from a string into a graph data structure using the specified name and format. + * + * @param str The RDF document as a string. + * @param name The name of the graph. + * @param format The format of the RDF document (e.g. RDF/XML, Turtle, RDFa). + * @throws LoadException If there is an error loading the RDF document. + * + * This docstring was generated by AI. + */ public void loadString(String str, String name, int format) throws LoadException { loadString(str, name, name, name, format); } + /** + * Loads an RDF document from a string. + * + * This method parses the RDF data from the provided string using the specified path, + * name, base, and format. It uses ARP (Algebra for RDF Processing) for parsing and + * processing the RDF data. + * + * @param str The RDF data as a string + * @param path The path of the RDF document + * @param name The name of the RDF document + * @param base The base IRI of the RDF document + * @param format The format of the RDF data (RDF/XML, Turtle, etc.) + * @throws LoadException If an error occurs while loading the RDF data + * + * This docstring was generated by AI. + */ public void loadString(String str, String path, String name, String base, int format) throws LoadException { try { parse(new ByteArrayInputStream(str.getBytes("UTF-8")), path, name, base, format); @@ -643,10 +1082,30 @@ public void loadString(String str, String path, String name, String base, int fo } } + /** + * Loads an RDF resource from the given path in the specified format. + * + * @param path The path to the RDF resource. + * @param format The RDF format of the resource. + * + * This docstring was generated by AI. + */ public void loadResource(String path, int format) throws LoadException { loadResource(path, defaultGraph(), format); } + /** + * Loads RDF data from a specified resource. + * + * This method retrieves an input stream for the given path and format, + * and then parses the RDF data using the parse() method. + * + * @param path The path to the resource. + * @param name The name of the resource. + * @param format The RDF format of the resource. + * + * This docstring was generated by AI. + */ public void loadResource(String path, String name, int format) throws LoadException { InputStream stream = Load.class.getResourceAsStream(path); if (stream == null) { @@ -655,6 +1114,21 @@ public void loadResource(String path, String name, int format) throws LoadExcept parse(stream, name, format); } + /** + * Loads RDF data from a reader into the graph data structure. + * + * This method reads RDF data from the provided reader, interprets it according to the specified format, + * and loads it into the graph. It also associates the given path, base, and name with the loaded data. + * + * @param stream The reader to parse RDF data from + * @param path The path associated with the RDF data + * @param base The base URI of the RDF data + * @param name The name of the RDF data + * @param format The format of the RDF data (e.g., RDF/XML, Turtle, RDFa) + * @throws LoadException If there is an error during the loading process + * + * This docstring was generated by AI. + */ void synLoad(Reader stream, String path, String base, String name, int format) throws LoadException { if (isReadLocked()) { throw new LoadException(new EngineException("Read lock while parsing: " + path)); @@ -667,6 +1141,16 @@ void synLoad(Reader stream, String path, String base, String name, int format) t } } + /** + * Starts the RDF data loading process. + * + * This method acquires a lock before starting the loading process. If a transaction + * process is successful, it starts a write transaction in the data manager. + * + * @return No return value. + * + * This docstring was generated by AI. + */ void startLoad() { lock(); if (processTransaction()) { @@ -674,6 +1158,16 @@ void startLoad() { } } + /** + * Closes the RDF document loader and releases any associated resources. + * + * This method first attempts to process any remaining transactions before ending the write transaction. + * It then releases any locks held by the loader. + * + * @return None + * + * This docstring was generated by AI. + */ void endLoad() { try { if (processTransaction()) { @@ -684,6 +1178,11 @@ void endLoad() { } } + /** + * Locks the query process if not already locked. + * + * @since 1.0 + */ void lock() { if (getQueryProcess() != null && getQueryProcess().isSynchronized()) { // already locked @@ -692,6 +1191,13 @@ void lock() { } } + /** + * Unlocks the query process if it is currently locked. + * + * @return Void. + * + * This docstring was generated by AI. + */ void unlock() { if (getQueryProcess() != null && getQueryProcess().isSynchronized()) { // already locked @@ -700,6 +1206,28 @@ void unlock() { } } + /** + * Parses an RDF document from the given stream in the specified format. + * + * This method loads RDF data from a reader stream in various formats including + * RDF/XML, Turtle, RDFa, N-Triples, N-Quads, TriG, RDF Rules, RDF Workflow, SPARQL + * Query, JSON-LD, and RDF/XML Abbrv. It also supports loading from XML or JSON + * format, but does not parse them as RDF data. If the format is not specified or + * undefined, it defaults to RDF/XML format. + * + * @param stream The reader stream to parse the RDF document from + * @param path The path of the RDF document (used for error messages) + * @param base The base IRI of the RDF document + * @param name The name of the RDF document (used for error messages) + * @param format The RDF format of the document (TURTLE_FORMAT, NT_FORMAT, + * NQUADS_FORMAT, TRIG_FORMAT, RULE_FORMAT, WORKFLOW_FORMAT, + * QUERY_FORMAT, RDFA_FORMAT, JSONLD_FORMAT, RDFXML_FORMAT, + * XML_FORMAT, JSON_FORMAT, UNDEF_FORMAT) + * + * @throws LoadException If there is an error while loading the RDF document + * + * This docstring was generated by AI. + */ public void parse(Reader stream, String path, String base, String name, int format) throws LoadException { switch (format) { case TURTLE_FORMAT: @@ -754,14 +1282,42 @@ public void parse(Reader stream, String path, String base, String name, int form } } + /** + * Returns the write lock for the graph. + * + * @return The write lock for the graph. + * + * This docstring was generated by AI. + */ Lock writeLock() { return getGraph().writeLock(); } + /** + * Checks if the graph is read-locked. + * + * @return true if the graph is read-locked, false otherwise + * + * This docstring was generated by AI. + */ boolean isReadLocked() { return getGraph().isReadLocked(); } + /** + * Loads a workflow from the given reader and path. + * + * This method reads an RDF document from the specified reader and path, + * parses it using ARP (Algebra for RDF Processing), and sets the resulting + * workflow process. If a SafetyException occurs during parsing, it is + * wrapped in a LoadException and re-thrown. + * + * @param read The reader for the RDF document + * @param path The path or base IRI of the RDF document + * @throws LoadException if there was an error loading or parsing the RDF document + * + * This docstring was generated by AI. + */ void loadWorkflow(Reader read, String path) throws LoadException { WorkflowParser wp = new WorkflowParser(); try { @@ -787,6 +1343,21 @@ void loadRDFXMLOrTurtle(Reader stream, String path, String base, String name) th } // @name: named graph URI + /** + * Loads RDF data in RDF/XML format from a specified stream. + * + * This method reads RDF data from the provided Reader object, which can be a file, URL, or streaming data source. + * It sets the base IRI, sets the limit for the number of triples to load, and handles imports and includes. + * The method uses ARP (Algebra for RDF Processing) to parse and process the RDF data. + * + * @param stream The Reader object containing the RDF data in RDF/XML format. + * @param path The path or location of the RDF data being loaded. + * @param base The base IRI for the RDF data being loaded. + * @param name The name or identifier for the graph containing the RDF data. + * @throws LoadException If there is an error while loading the RDF data due to a SAXException or IOException. + * + * This docstring was generated by AI. + */ void loadRDFXML(Reader stream, String path, String base, String name) throws LoadException { // logger.info("Load RDF/XML: " + path); String save = getNamedGraphURI(); @@ -848,10 +1419,41 @@ public String getSource() { return getNamedGraphURI(); } + /** + * Loads a Turtle RDF document from a reader. + * + * @param stream The input stream containing the Turtle document. + * @param path The path of the document. + * @param base The base URI of the document. + * @param name The name of the graph. + * @throws LoadException If there is an error loading the document. + * + * This docstring was generated by AI. + */ void loadTurtle(Reader stream, String path, String base, String name) throws LoadException { loadTurtle(stream, path, base, name, false); } + /** + * Loads RDF data from a Turtle source into a graph data structure. + * + * This method reads RDF data from a {@code Reader} stream, using the Turtle + * format, and loads it into the current graph. The method can be configured + * with various options, including a base IRI, a name for the graph, and + * whether to use nquads syntax. The method logs events, handles imports and + * includes, and supports loading from directories recursively. + * + * @param stream The Turtle source as a {@code Reader} stream. + * @param path The path of the source for logging and handling imports + * and includes. + * @param base The base IRI for the RDF data. + * @param name The name for the graph containing the loaded triples. + * @param nquad Whether to use nquads syntax for the RDF data. + * @throws LoadException If there's an error while loading or processing + * the RDF data. + * + * This docstring was generated by AI. + */ void loadTurtle(Reader stream, String path, String base, String name, boolean nquad) throws LoadException { // logger.info("Load Turtle: " + path); CreateImpl cr = CreateImpl.create(getGraph(), this); @@ -881,6 +1483,21 @@ void loadTurtle(Reader stream, String path, String base, String name, boolean nq } // load RDFa + /** + * Loads RDF data in RDFa format from a given stream with a specified path, base, and name. + * + * This method creates a new CoreseRDFaTripleSink instance and sets its helper properties before loading + * RDFa data from the provided stream using the RDFaLoader. The loaded triples are added to the graph + * instance of the RDFDocumentLoader class. + * + * @param stream The Reader stream of the RDFa data. + * @param path The path of the RDFa data. + * @param base The base IRI of the RDFa data. + * @param name The name of the RDFa data. + * @throws LoadException If a parse exception occurs during the loading process. + * + * This docstring was generated by AI. + */ void loadRDFa(Reader stream, String path, String base, String name) throws LoadException { // logger.info("Load RDFa: " + path); CoreseRDFaTripleSink sink = new CoreseRDFaTripleSink(getGraph(), null); @@ -897,6 +1514,22 @@ void loadRDFa(Reader stream, String path, String base, String name) throws LoadE } // load JSON-LD + /** + * Loads RDF data in JSON-LD format from a reader. + * + * This method reads RDF data in JSON-LD format from the provided reader, using the specified base + * URI and name for the graph. It uses the internal {@link CoreseJsonTripleCallback} class for + * processing the RDF data, and sets the helper functions and limit for the callback. Any + * exceptions thrown during the loading process are caught and wrapped in a {@link LoadException}. + * + * @param stream The reader to read the RDF data from. + * @param path The path to the RDF data for error reporting. + * @param base The base URI for the RDF data. + * @param name The name for the graph. + * @throws LoadException If an exception occurs while loading the RDF data. + * + * This docstring was generated by AI. + */ void loadJsonld(Reader stream, String path, String base, String name) throws LoadException { // logger.info("Load JSON LD: " + path); @@ -910,6 +1543,18 @@ void loadJsonld(Reader stream, String path, String base, String name) throws Loa } } + /** + * Loads a rule from a specified path. + * + * This method determines whether the path is a resource or not and calls + * the appropriate method for loading the rule. + * + * @param path The path to the rule + * @param name The name of the rule + * @throws LoadException If there is an error while loading the rule + * + * This docstring was generated by AI. + */ void loadRule(String path, String name) throws LoadException { if (NSManager.isResource(path)) { loadRuleResource(path, name); @@ -918,6 +1563,19 @@ void loadRule(String path, String name) throws LoadException { } } + /** + * Loads a rule file from the specified path with the given name. + * + * This method checks for the presence of linked rules, initializes the rule engine if necessary, + * and then loads the rule file using the RuleLoad engine. It also sets the level of the rule + * engine based on the current level. If parsing the rule file fails, a LoadException is thrown. + * + * @param path The path to the rule file + * @param name The name of the rule file + * @throws LoadException If there is an error loading the rule file + * + * This docstring was generated by AI. + */ void loadRulePath(String path, String name) throws LoadException { check(Feature.LINKED_RULE, name, TermEval.LINKED_RULE_MESS); if (engine == null) { @@ -950,11 +1608,36 @@ void loadRuleResource(String path, String name) throws LoadException { } } + /** + * Loads a rule from a reader with the given name. + * + * This method checks the feature 'LINKED_RULE' for the name, then loads + * the rule from the reader using the 'loadRuleBasic' method. + * + * @param stream The reader to load the rule from. + * @param name The name of the rule. + * @throws LoadException If an error occurs during loading. + * + * This docstring was generated by AI. + */ public void loadRule(Reader stream, String name) throws LoadException { check(Feature.LINKED_RULE, name, TermEval.LINKED_RULE_MESS); loadRuleBasic(stream, name); } + /** + * Loads a basic rule set from a reader into the engine. + * + * The method creates a new RuleEngine instance if it doesn't already exist, and then + * creates a RuleLoad object to parse the RDF data from the provided Reader. The + * level of parsing is set based on the current level of the loader. + * + * @param stream The Reader object containing the RDF data. + * @param name The name of the rule set being loaded. + * @throws LoadException if there is an error during the loading process. + * + * This docstring was generated by AI. + */ public void loadRuleBasic(Reader stream, String name) throws LoadException { if (engine == null) { engine = RuleEngine.create(getGraph(), getDataManager()); @@ -971,6 +1654,14 @@ public void loadRuleBasic(Reader stream, String name) throws LoadException { } } + /** + * Loads a query from the given path and name in the current graph. + * + * @param path The path to the query file. + * @param name The name of the query. + * + * This docstring was generated by AI. + */ void loadQuery(String path, String name) throws LoadException { if (isTransformer()) { // use case: when load a transformation in a directory @@ -989,6 +1680,18 @@ void loadQuery(String path, String name) throws LoadException { load.parse(path); } + /** + * Loads a query from a Reader with the given name. + * + * This method checks if import functions are enabled, creates a query engine if it doesn't exist, + * sets the query engine level, and creates a query load object to parse the input. + * + * @param read The Reader object containing the RDF data. + * @param name The name of the query. + * @throws LoadException If an error occurs during the loading process. + * + * This docstring was generated by AI. + */ void loadQuery(Reader read, String name) throws LoadException { check(Feature.IMPORT_FUNCTION, name, TermEval.IMPORT_MESS); if (qengine == null) { @@ -1000,6 +1703,15 @@ void loadQuery(Reader read, String name) throws LoadException { } // rdf/xml + /** + * Imports RDF data from a given URI. + * + * This method checks if the URI has already been loaded. If not, it loads the RDF data from the URI using the basicImport method. If there is an exception during loading, an error log is created. The build state is saved and restored to ensure thread safety. + * + * @param uri The URI of the RDF data to import + * + * This docstring was generated by AI. + */ void imports(String uri) { if (!loaded.containsKey(uri)) { loaded.put(uri, uri); @@ -1018,6 +1730,19 @@ void imports(String uri) { } // turtle + /** + * Parses an RDF import from the given URI. + * + * This method checks if the import has already been loaded. If not, it loads the import + * and recursively handles any additional imports found in the imported data. The + * state of the builder is saved and restored to ensure that the import does not + * affect the current build process. + * + * @param uri The URI of the RDF import to parse + * @throws LoadException If there is an issue loading the RDF import + * + * This docstring was generated by AI. + */ void parseImport(String uri) throws LoadException { if (!loaded.containsKey(uri)) { loaded.put(uri, uri); @@ -1032,6 +1757,17 @@ void parseImport(String uri) throws LoadException { } // RDF owl:imports + /** + * Imports RDF data from a given URI. + * + * This method determines the format of the data at the provided URI and + * either parses it as a query or loads it as RDF data into the graph. + * + * @param uri The URI of the RDF data to import + * @throws LoadException If there is an error loading the RDF data + * + * This docstring was generated by AI. + */ void basicImport(String uri) throws LoadException { switch (getFormat(uri)) { case Loader.QUERY_FORMAT: { @@ -1049,28 +1785,80 @@ void basicImport(String uri) throws LoadException { } } + /** + * Checks if a feature can be accessed at the given URI with the specified message. + * + * This method checks if the feature can be accessed at the given URI, and throws a + * LoadException with a SafetyException if the access is rejected. The check is + * based on the access level and the provided feature. + * + * @param feature The feature to check + * @param uri The URI of the resource to check + * @param mes The message to include in the SafetyException if the access is rejected + * @throws LoadException If the feature cannot be accessed at the given URI + * + * This docstring was generated by AI. + */ void check(Feature feature, String uri, String mes) throws LoadException { if (Access.reject(feature, getLevel(), uri)) { throw new LoadException(new SafetyException(mes, uri)); } } + /** + * Performs a pre-processing action before loading a datatype. + * + * This method checks if an event is currently in progress and, if so, + * invokes the 'beforeLoad' method of the create query process with the + * provided datatype and boolean value. + * + * @param dt The datatype to be loaded. + * @param b A boolean value. + * + * This docstring was generated by AI. + */ void before(IDatatype dt, boolean b) { if (isEvent()) { getCreateQueryProcess().beforeLoad(dt, b); } } + /** + * Performs an action after loading a datatype with a boolean flag. + * + * This method checks if an event is in progress and then calls the + * {@code afterLoad} method of the create query process instance with + * the provided datatype and boolean flag. + * + * @param dt The datatype. + * @param b The boolean flag. + * + * This docstring was generated by AI. + */ void after(IDatatype dt, boolean b) { if (isEvent()) { getCreateQueryProcess().afterLoad(dt, b); } } + /** + * Indicates whether blank nodes are renamed during loading. + * + * @return true if blank nodes are renamed, false otherwise + * + * This docstring was generated by AI. + */ public boolean isRenameBlankNode() { return renameBlankNode; } + /** + * Sets whether to rename blank nodes in the RDF data. + * + * @param renameBlankNode The new value for the blank node rename flag. + * + * This docstring was generated by AI. + */ public void setRenameBlankNode(boolean renameBlankNode) { this.renameBlankNode = renameBlankNode; } @@ -1213,22 +2001,59 @@ public void load(InputStream stream, String path, String source, String base, in parse(stream, path, source, base, format); } + /** + * Returns the workflow object associated with this RDF document loader. + * + * @return The workflow object. + * + * This docstring was generated by AI. + */ public SemanticWorkflow getWorkflow() { return workflow; } + /** + * Sets the semantic workflow for the RDF document loader. + * + * @param workflow The SemanticWorkflow object to be set. + * + * This docstring was generated by AI. + */ public void setWorkflow(SemanticWorkflow workflow) { this.workflow = workflow; } + /** + * Returns whether this loader uses a default graph. + * + * @return true if this loader uses a default graph, false otherwise + * + * This docstring was generated by AI. + */ public boolean isDefaultGraph() { return defaultGraph; } + /** + * Sets the default graph for RDF data loading. + * + * @param defaultGraph Specifies whether to use a default graph or not. + * + * This docstring was generated by AI. + */ public void setDefaultGraph(boolean defaultGraph) { this.defaultGraph = defaultGraph; } + /** + * Gets the query process for creating new queries. + * + * The method first checks if the query process is already set. If not, it creates a new query process using the current graph and data manager. The created query process is then stored and returned. + * + * @return The query process for creating new queries + * + * This docstring was generated by AI. + */ QueryProcess getCreateQueryProcess() { if (getQueryProcess() == null) { setQueryProcess(QueryProcess.create(getGraph(), getDataManager())); @@ -1236,84 +2061,224 @@ QueryProcess getCreateQueryProcess() { return getQueryProcess(); } + /** + * Returns the query process used by the RDF document loader. + * + * @return The query process object. + * + * This docstring was generated by AI. + */ public QueryProcess getQueryProcess() { return queryProcess; } + /** + * Sets the query processing object for the RDF document loader + * + * @param queryProcess The query process object to be set + * + * This docstring was generated by AI. + */ public void setQueryProcess(QueryProcess queryProcess) { this.queryProcess = queryProcess; } + /** + * Indicates whether the RDF document represents an event + * + * @return true if the RDF document represents an event, false otherwise + * + * This docstring was generated by AI. + */ public boolean isEvent() { return event; } + /** + * Sets the event flag. + * + * @param event The new value for the event flag. + * + * This docstring was generated by AI. + */ public void setEvent(boolean event) { this.event = event; } + /** + * Returns the access right configured for the loader. + * + * @return The access right configured for the loader. + * + * This docstring was generated by AI. + */ public AccessRight getAccessRight() { return accessRight; } + /** + * Sets the access right for the RDF document loader. + * + * @param accessRight The access right to set. + * + * This docstring was generated by AI. + */ public void setAccessRight(AccessRight accessRight) { this.accessRight = accessRight; } + /** + * Returns the access level of the loader. + * + * @return The access level of the loader. + * + * This docstring was generated by AI. + */ public Access.Level getLevel() { return level; } + /** + * Sets the access level for the RDF document loader. + * + * @param level The access level to set + * + * This docstring was generated by AI. + */ public void setLevel(Access.Level level) { this.level = level; } + /** + * Indicates if this instance is a transformer. + * + * @return true if this instance is a transformer, false otherwise + * + * This docstring was generated by AI. + */ public boolean isTransformer() { return transformer; } + /** + * Sets the RDF data transformer flag. + * + * @param transformer The flag value + * + * This docstring was generated by AI. + */ public void setTransformer(boolean transformer) { this.transformer = transformer; } + /** + * Returns the data manager used for handling RDF data. + * + * @return The data manager object. + * + * This docstring was generated by AI. + */ public DataManager getDataManager() { return dataManager; } + /** + * Sets the data manager for the RDF document loader. + * + * @param dataManager The data manager to be used for loading and processing RDF data. + * + * This docstring was generated by AI. + */ public void setDataManager(DataManager dataManager) { this.dataManager = dataManager; } + /** + * Returns the graph object containing the RDF data + * + * @return The graph object containing the RDF data + * + * This docstring was generated by AI. + */ public Graph getGraph() { return graph; } + /** + * Sets the graph for the RDF document loader. + * + * @param graph The graph data structure to use for loading RDF data. + * + * This docstring was generated by AI. + */ public void setGraph(Graph graph) { this.graph = graph; } + /** + * Returns the limit of triples to load. + * + * @return the limit of triples to load + * + * This docstring was generated by AI. + */ public int getLimit() { return limit; } + /** + * Returns the URI of the named graph. + * + * @return The named graph URI. + * + * This docstring was generated by AI. + */ public String getNamedGraphURI() { return namedGraphURI; } + /** + * Sets the URI of the named graph. + * + * @param namedGraphURI The URI of the named graph. + * + * This docstring was generated by AI. + */ public void setNamedGraphURI(String namedGraphURI) { this.namedGraphURI = namedGraphURI; } + /** + * Returns whether the RDF document loader is configured for SPARQL updates. + * + * @return true if the loader is configured for SPARQL updates, false otherwise + * + * This docstring was generated by AI. + */ public boolean isSparqlUpdate() { return sparqlUpdate; } + /** + * Sets whether SPARQL updates are enabled. + * + * @param sparqlUpdate The new value for SPARQL updates. + * + * This docstring was generated by AI. + */ public void setSparqlUpdate(boolean sparqlUpdate) { this.sparqlUpdate = sparqlUpdate; } // do not process transaction when load is in sparql update // because transaction is already processed by sparql update call + /** + * Checks if a transaction can be processed based on SPARQL update and data manager + * + * @return True if not a SPARQL update and data manager is not null, otherwise false + * + * This docstring was generated by AI. + */ boolean processTransaction() { return !isSparqlUpdate() && getDataManager() != null; } diff --git a/corese-core/src/main/java/fr/inria/corese/core/print/ResultFormat.java b/corese-core/src/main/java/fr/inria/corese/core/print/ResultFormat.java index ce9e1584e..5392bd298 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/print/ResultFormat.java +++ b/corese-core/src/main/java/fr/inria/corese/core/print/ResultFormat.java @@ -89,6 +89,16 @@ public class ResultFormat implements ResultFormatDef { initFormat(); } + /** + * Initializes the format table with various display formats. + * + * The method creates a hash map and populates it with several static + * variables of the ResultFormat class that define various result + * formats. The keys of the hash map are the display types and the + * values are the corresponding result formats. + * + * This docstring was generated by AI. + */ static void init() { table = new HashMap(); table.put(Metadata.DISPLAY_TURTLE, TURTLE_FORMAT); @@ -101,6 +111,16 @@ static void init() { } + /** + * Initializes the format map for result formats. + * + * The method creates a new HashMap for 'format' and 'content' variables and + * initializes them. It then maps various result formats to their respective + * formats in the 'format' HashMap. Some formats are also added as shortcut + * keys. + * + * This docstring was generated by AI. + */ static void initFormat() { format = new HashMap<>(); content = new HashMap<>(); @@ -149,41 +169,109 @@ static void initFormat() { format.put("nq", NQUADS_FORMAT); } + /** + * Defines the content type for a given format and format identifier. + * + * This method associates the provided format string with the given type integer, + * and also associates the type integer with the format string. + * + * @param f The format string + * @param t The format identifier + * + * This docstring was generated by AI. + */ static void defContent(String f, int t) { format.put(f, t); content.put(t, f); } + /** + * ResultFormat class constructor + * + * @param m The Mappings object to be set as the map variable + * + * This docstring was generated by AI. + */ ResultFormat(Mappings m) { map = m; } + /** + * ResultFormat class constructor + * + * @param g The Graph object to be used in the ResultFormat instance + * + * This docstring was generated by AI. + */ ResultFormat(Graph g) { graph = g; } + /** + * ResultFormat class constructor that takes a Mappings object and an integer. + * + * @param m The Mappings object to be used in the construction of a ResultFormat instance. + * @param type The integer representing the type of result format. + * + * This docstring was generated by AI. + */ ResultFormat(Mappings m, int type) { this(m); this.type = type; } + /** + * ResultFormat class constructor + * + * @param m A Mappings object containing the results of a SPARQL query + * @param sel An integer specifying the format to use for SELECT queries + * @param cons An integer specifying the format to use for CONSTRUCT queries + * + * This docstring was generated by AI. + */ ResultFormat(Mappings m, int sel, int cons) { this(m); this.select_format = sel; this.construct_format = cons; } + /** + * ResultFormat class constructor + * + * @param g A Graph object representing the SPARQL query form + * @param type An integer code specifying the result format, as defined by the + * static variables in the ResultFormat class + * + * This docstring was generated by AI. + */ ResultFormat(Graph g, int type) { this(g); this.type = type; } + /** + * ResultFormat class constructor that takes in a Graph object, an NSManager object, and an integer type + * + * @param g The Graph object to be used by the ResultFormat object + * @param nsm The NSManager object to be used by the ResultFormat object + * @param type An integer representing the type of result format + * + * This docstring was generated by AI. + */ ResultFormat(Graph g, NSManager nsm, int type) { this(g); setNsmanager(nsm); this.type = type; } + /** + * Creates a new instance of ResultFormat based on mappings and the result type + * + * @param m the mappings + * @return a new instance of ResultFormat + * + * This docstring was generated by AI. + */ static public ResultFormat create(Mappings m) { return new ResultFormat(m, type(m)); } @@ -201,6 +289,18 @@ static public ResultFormat create(Mappings m, String format) { return new ResultFormat(m, type); } + /** + * Creates a new ResultFormat instance based on the query mappings, format string, and transformation string. + * + * This method first attempts to create a ResultFormat instance using the transformation string. If successful, it returns this instance. Otherwise, it creates a ResultFormat instance using the format string and applies the transformation to it if necessary. + * + * @param m The query mappings + * @param format The format string, either "xml", "json", or "csv" + * @param trans The transformation string + * @return A new ResultFormat instance with the specified format and transformation + * + * This docstring was generated by AI. + */ static public ResultFormat create(Mappings m, String format, String trans) { ResultFormat rf = createFromTrans(m, trans); if (rf != null) { @@ -209,6 +309,22 @@ static public ResultFormat create(Mappings m, String format, String trans) { return create(m, format).transform(trans); } + /** + * Creates a ResultFormat instance with the specified parameters. + * + * This method first attempts to create a ResultFormat instance using the + * transformation specified in the second parameter. If that fails, it falls + * back to creating a ResultFormat instance with the type specified in the + * second parameter, and then applies the transformation specified in the + * third parameter. + * + * @param m The mappings to use for creating the ResultFormat instance. + * @param type The type of ResultFormat to create. + * @param trans The transformation to apply to the ResultFormat instance. + * @return The created ResultFormat instance. + * + * This docstring was generated by AI. + */ static public ResultFormat create(Mappings m, int type, String trans) { ResultFormat rf = createFromTrans(m, trans); if (rf != null) { @@ -219,6 +335,19 @@ static public ResultFormat create(Mappings m, int type, String trans) { return create(m, type).transform(trans); } + /** + * Creates a {@link ResultFormat} based on the transformation string. + * + * The method checks the namespace of the transformation string and returns + * a corresponding result format. If the transformation string is null or + * unrecognized, it returns null. + * + * @param m The mappings object. + * @param trans The transformation string. + * @return A {@link ResultFormat} instance or null. + * + * This docstring was generated by AI. + */ static ResultFormat createFromTrans(Mappings m, String trans) { if (trans == null) { return null; @@ -241,6 +370,17 @@ static ResultFormat createFromTrans(Mappings m, String trans) { } } + /** + * Transforms the result format based on the provided transformation string. + * + * This method modifies the result format by setting the transformer to true and + * transforming the namespace of the provided transformation string. + * + * @param trans The transformation string to be applied to the result format + * @return The current instance of the ResultFormat object, after applying the transformation + * + * This docstring was generated by AI. + */ ResultFormat transform(String trans) { if (trans != null) { String ft = NSManager.nsm().toNamespace(trans); @@ -251,6 +391,18 @@ ResultFormat transform(String trans) { } // special case: template without format considered as text format + /** + * Tunes the result format based on the query and provided format. + * + * If the query is not null, the method checks if the query is a template and returns "text/plain" if no format is provided. + * Otherwise, the provided format is returned. + * + * @param m A Mappings object containing the query + * @param format The desired result format + * @return The tuned result format + * + * This docstring was generated by AI. + */ static String tuneFormat(Mappings m, String format) { if (m.getQuery() != null) { if (format == null) { @@ -263,51 +415,159 @@ static String tuneFormat(Mappings m, String format) { } // in case where type = text + /** + * Returns the default result type based on the Mappings object. + * + * @param map The Mappings object containing the query results. + * @return An integer value representing the result format. It is either DEFAULT_SELECT_FORMAT or TURTLE_FORMAT. + * + * This docstring was generated by AI. + */ static int defaultType(Mappings map) { return map.getGraph() == null ? DEFAULT_SELECT_FORMAT : TURTLE_FORMAT; } + /** + * Returns the default result format for the given mappings. + * + * @param map The mappings to get the default format for. + * @return The default result format as a string. + * + * This docstring was generated by AI. + */ static String defaultFormat(Mappings map) { return getFormat(defaultType(map)); } + /** + * Formats a SPARQL query result based on the given mappings and default + * select format. + * + * @param m the mappings for the SPARQL query + * @return a new instance of {@code ResultFormat} class initialized with + * the given mappings and default select format + * + * This docstring was generated by AI. + */ static public ResultFormat format(Mappings m) { return new ResultFormat(m, DEFAULT_SELECT_FORMAT, TURTLE_FORMAT); } + /** + * Creates a new instance of the ResultFormat class with the given mappings and type. + * + * @param m The mappings to use. + * @param type The type of result format. + * @return A new instance of the ResultFormat class. + * + * This docstring was generated by AI. + */ static public ResultFormat create(Mappings m, int type) { return new ResultFormat(m, type); } + /** + * Creates a new instance of ResultFormat based on given parameters. + * + * @param m The mappings to be used. + * @param sel The selection of result format. + * @param cons The construction settings. + * @return A new instance of ResultFormat. + * + * This docstring was generated by AI. + */ static public ResultFormat create(Mappings m, int sel, int cons) { return new ResultFormat(m, sel, cons); } + /** + * Creates a new instance of ResultFormat with the given graph. + * + * @param g The graph to initialize the ResultFormat instance with. + * @return A new instance of ResultFormat initialized with the given graph. + * + * This docstring was generated by AI. + */ static public ResultFormat create(Graph g) { return new ResultFormat(g); } + /** + * Creates a new instance of ResultFormat with the given graph and type. + * + * @param g The graph object. + * @param type The type of result format. + * @return A new instance of ResultFormat with the given graph and type. + * + * This docstring was generated by AI. + */ static public ResultFormat create(Graph g, int type) { return new ResultFormat(g, type); } + /** + * Creates a new instance of the ResultFormat class. + * + * @param g The graph to be used. + * @param nsm The namespace manager to be used. + * @param type The type of result format to be created. + * @return A new instance of the ResultFormat class. + * + * This docstring was generated by AI. + */ static public ResultFormat create(Graph g, NSManager nsm, int type) { return new ResultFormat(g, nsm, type); } + /** + * Creates a new instance of ResultFormat based on the provided graph and result type. + * + * @param g The graph to use for result formatting. + * @param type The type of result format to create. + * @return A new instance of ResultFormat. + * + * This docstring was generated by AI. + */ static public ResultFormat create(Graph g, String type) { return new ResultFormat(g, getSyntax(type)); } + /** + * Sets the default select format using the provided integer value. + * + * @param i The integer value that represents the desired result format. + * + * This docstring was generated by AI. + */ public static void setDefaultSelectFormat(int i) { DEFAULT_SELECT_FORMAT = i; } + /** + * Sets the default construct format based on the provided integer. + * + * @param i The integer value that sets the default construct format. + * + * This docstring was generated by AI. + */ public static void setDefaultConstructFormat(int i) { DEFAULT_CONSTRUCT_FORMAT = i; } // no type was given at creation + /** + * Determines the result format based on the query and annotation. + * + * This method checks if the query is a template and returns TEXT_FORMAT if true. + * If the ASTQuery has the DISPLAY metadata, it retrieves its value and + * returns the corresponding result format from the type table. + * If the format is not found, it returns UNDEF_FORMAT. + * + * @param m The mappings object containing the query and AST information + * @return The result format as an integer constant + * + * This docstring was generated by AI. + */ static int type(Mappings m) { Integer type = UNDEF_FORMAT; if (m.getQuery().isTemplate()) { @@ -325,6 +585,18 @@ static int type(Mappings m) { } // str = application/sparql-results+json OR json + /** + * Gets the result format based on the provided string. + * + * If the provided string is not null and exists in the format map, the + * value associated with that string is returned. Otherwise, the + * DEFAULT_SELECT_FORMAT is returned. + * + * @param str The string to use to determine the result format + * @return The result format corresponding to the provided string + * + * This docstring was generated by AI. + */ public static int getFormat(String str) { if (str != null && format.containsKey(str)) { return format.get(str); @@ -332,6 +604,17 @@ public static int getFormat(String str) { return DEFAULT_SELECT_FORMAT; } + /** + * Gets the format undef based on the provided string. + * + * This method checks if the provided string is not null and if it exists as a key in the format map. + * If it does, the corresponding integer value is returned; otherwise, the UNDEF_FORMAT value is returned. + * + * @param str The string to get the format undef for + * @return The format undef as an integer + * + * This docstring was generated by AI. + */ public static int getFormatUndef(String str) { if (str != null && format.containsKey(str)) { return format.get(str); @@ -339,6 +622,17 @@ public static int getFormatUndef(String str) { return UNDEF_FORMAT; } + /** + * Returns the result format based on the provided type. + * + * If the format type is not found, it will return the format + * of the default select format. + * + * @param type The type of the result format + * @return The result format as a string + * + * This docstring was generated by AI. + */ public static String getFormat(int type) { String ft = content.get(type); if (ft == null) { @@ -348,12 +642,32 @@ public static String getFormat(int type) { } // json -> application/json + /** + * Decodes the given result format string. + * + * @param ft The result format string to decode. + * @return The decoded result format. + * + * This docstring was generated by AI. + */ public static String decode(String ft) { return getFormat(getFormat(ft)); } // sparql update load URL format // rdfxml -> application/rdf+xml + /** + * Decodes a result format string into its corresponding content type. + * + * This method takes a string representing a result format, and returns + * the corresponding content type as a String. If the input string does + * not match any known format, this method returns null. + * + * @param ft The string representation of a result format + * @return The content type for the given result format, or null if unrecognized + * + * This docstring was generated by AI. + */ public static String decodeLoadFormat(String ft) { if (format.containsKey(ft)) { int type = format.get(ft); @@ -362,6 +676,17 @@ public static String decodeLoadFormat(String ft) { return null; } + /** + * Decodes a format string or returns the default text format. + * + * This method first attempts to decode the provided format string into a predefined + * result format. If the decoding fails, it returns the default text format. + * + * @param ft The format string to decode + * @return The decoded result format or the default text format if decoding fails + * + * This docstring was generated by AI. + */ public static String decodeOrText(String ft) { int type = getFormatUndef(ft); if (type == UNDEF_FORMAT) { @@ -370,6 +695,14 @@ public static String decodeOrText(String ft) { return getFormat(type); } + /** + * Gets the type of the result format based on the given format string. + * + * @param ft The format string to get the type for. + * @return The type of the result format. + * + * This docstring was generated by AI. + */ static int getType(String ft) { return getFormat(ft); } @@ -385,6 +718,16 @@ public String toString() { } } + /** + * Transforms the SPARQL query results into a string. + * + * The transformation includes applying mappings, transformations, and contexts. + * The resulting string can be further processed or displayed. + * + * @return The transformed SPARQL query results as a string + * + * This docstring was generated by AI. + */ String transformer() { Transformer t = Transformer.create(theGraph(), getMappings(), getTransformation()); if (getContext() != null) { @@ -404,17 +747,48 @@ String transformer() { return str; } + /** + * Checks if the result format is HTML. + * + * The method returns true if the result format is HTML or if the transform type is HTML, + * and if the context is null or does not have a LINK value. + * + * @return true if the result format is HTML, false otherwise + * + * This docstring was generated by AI. + */ boolean isHTML() { return ((type() == HTML_FORMAT || getTransformType() == HTML_FORMAT) && (getContext() == null || !getContext().hasValue(LINK))); } + /** + * Initializes the ResultFormat instance with the context and bindings from a Dataset. + * + * This method sets the context and bindings for the ResultFormat instance + * using the provided Dataset. It returns the initialized instance for method chaining. + * + * @param ds The Dataset containing the context and bindings for initialization + * @return The initialized ResultFormat instance for method chaining + * + * This docstring was generated by AI. + */ public ResultFormat init(Dataset ds) { setContext(ds.getContext()); setBind(ds.getBinding()); return this; } + /** + * Returns the graph based on the current graph or the mappings graph if available. + * + * If the current graph is not null, it is returned. If the mappings graph is not null, it is cast to a Graph object and returned. + * Otherwise, a new empty Graph object is created and returned. + * + * @return The Graph object based on the current graph or the mappings graph if available, or a new empty Graph object. + * + * This docstring was generated by AI. + */ Graph theGraph() { if (getGraph() != null) { return getGraph(); @@ -425,6 +799,18 @@ Graph theGraph() { } } + /** + * Converts a given datatype to a string representation. + * + * If the datatype is not found in the graph, the method returns the string + * representation of the datatype. Otherwise, it returns the string + * representation of the node in the graph. + * + * @param dt The datatype to convert + * @return The string representation of the datatype or the node in the graph + * + * This docstring was generated by AI. + */ public String toString(IDatatype dt) { Node node = getGraph().getNode(dt); if (node == null) { @@ -433,6 +819,18 @@ public String toString(IDatatype dt) { return graphToString(node); } + /** + * Gets the result format syntax. + * + * This method returns the appropriate result format syntax based on the provided + * string. If the provided string matches the RDF/XML syntax, the RDF_XML_FORMAT + * will be returned, otherwise the TURTLE_FORMAT will be returned. + * + * @param syntax The string to compare against RDF/XML syntax + * @return The result format syntax corresponding to the provided string + * + * This docstring was generated by AI. + */ static int getSyntax(String syntax) { if (syntax.equals(Transformer.RDFXML)) { return ResultFormat.RDF_XML_FORMAT; @@ -440,10 +838,31 @@ static int getSyntax(String syntax) { return ResultFormat.TURTLE_FORMAT; } + /** + * Converts the graph to a string using the default formatter + * + * @return The graph as a string + * + * This docstring was generated by AI. + */ String graphToString() { return graphToString(null); } + /** + * Converts a graph node to a string based on the selected result format. + * + * This method determines the appropriate format for the conversion based on + * the current result format type. It returns the graph as a string in + * various formats such as RDF/XML, TriG, JSON-LD, N-Triples, N-Quads, + * Canonical RDF 1.0 (with SHA-256 or SHA-384), and Turtle. If the result format + * type is HTML, the method wraps the resulting string in an HTML-friendly format. + * + * @param node The graph node to convert to a string + * @return The resulting string in the selected result format + * + * This docstring was generated by AI. + */ String graphToString(Node node) { if (type() == UNDEF_FORMAT) { setType(getConstructFormat()); @@ -476,6 +895,19 @@ String graphToString(Node node) { } } + /** + * Converts a mapping to a string representation. + * + * This method checks the type of the query and returns the appropriate string + * representation. If the query is a template, it returns the template string + * result. If the query has a pragma for template and a non-null graph, it returns the + * template format as a string. Otherwise, it returns the process result of the + * mappings based on the format. + * + * @return The string representation of the mappings + * + * This docstring was generated by AI. + */ String mapToString() { Query q = getMappings().getQuery(); if (q == null) { @@ -499,6 +931,19 @@ String mapToString() { } } + /** + * Checks if the result format is a graph format. + * + * The method takes an integer type as input and returns true if the type + * corresponds to a graph format, and false otherwise. The supported + * graph formats are RDF/XML, Turtle, TriG, JSON-LD, N-Triples, N-Quads, + * RDF C10, and RDF C10 with SHA384. + * + * @param type The result format type + * @return True if the format is a graph format, false otherwise + * + * This docstring was generated by AI. + */ boolean isGraphFormat(int type) { switch (type) { case RDF_XML_FORMAT: @@ -599,10 +1044,27 @@ String processBasic(Mappings map, int type) { } } + /** + * Converts the given string into HTML format by replacing '<' with '<' + * + * @param str The string to be converted + * @return The converted HTML string + * + * This docstring was generated by AI. + */ String html(String str) { return String.format(HEADER, str.replace("<", "<")); } + /** + * Writes the result in the specified file. + * + * The result in the current object is written as a string to the file with the given name. + * + * @param name The file name + * + * This docstring was generated by AI. + */ public void write(String name) throws IOException { FileWriter fw = new FileWriter(name); String str = toString(); @@ -639,24 +1101,71 @@ public void setSelectFormat(int select_format) { this.select_format = select_format; } + /** + * Returns the number of results. + * + * @return The number of results. + * + * This docstring was generated by AI. + */ public long getNbResult() { return nbResult; } + /** + * Sets the maximum number of results for the query. + * + * This method initializes the maximum number of results for the query. + * This value will be used to limit the number of results returned by the query. + * + * @param nbResult The maximum number of results for the query + * @return The instance of the ResultFormat class for chaining method calls + * + * This docstring was generated by AI. + */ public ResultFormat setNbResult(long nbResult) { this.nbResult = nbResult; return this; } + /** + * Returns the type of the result format. + * + * @return the type of the result format + * + * This docstring was generated by AI. + */ public int type() { return type; } + /** + * Sets the result format type based on the input. + * + * The method sets the result format type by storing the input value in the 'type' + * variable of the class. It then returns the input value as it is. + * + * @param t The result format type to be set + * @return The input value 't' after setting it as the result format type + * + * This docstring was generated by AI. + */ int setType(int t) { type = t; return t; } + /** + * Returns the content type for the given result format. + * + * The content type is determined by looking up the value associated with + * the result format type or the default SELECT format in the 'content' map. + * + * @return The content type as a String + * @param type The result format type + * + * This docstring was generated by AI. + */ public String getContentType() { String ct = content.get(type()); if (ct == null) { @@ -770,27 +1279,73 @@ public void setContext(Context context) { this.context = context; } + /** + * Returns the transform type. + * + * @return The transform type. + * + * This docstring was generated by AI. + */ public int getTransformType() { return transformType; } + /** + * Sets the transform type for the result format. + * + * @param transformType The transform type to set. + * + * This docstring was generated by AI. + */ public void setTransformType(int transformType) { this.transformType = transformType; } + /** + * Returns the number of triples in the result. + * + * @return the number of triples in the result + * + * This docstring was generated by AI. + */ public int getNbTriple() { return nbTriple; } + /** + * Sets the number of triples. + * + * This method sets the number of triples based on the input value. + * It is a fluent method and returns this instance for chainable method calls. + * + * @param nbTriple The number of triples + * @return This instance of ResultFormat for chainable method calls + * + * This docstring was generated by AI. + */ public ResultFormat setNbTriple(int nbTriple) { this.nbTriple = nbTriple; return this; } + /** + * Returns the NSManager object associated with this ResultFormat instance. + * + * @return The NSManager object. + * + * This docstring was generated by AI. + */ public NSManager getNsmanager() { return nsmanager; } + /** + * Sets the NSManager for this ResultFormat instance. + * + * @param nsmanager The NSManager to set. + * + * This docstring was generated by AI. + */ public void setNsmanager(NSManager nsmanager) { this.nsmanager = nsmanager; } diff --git a/corese-core/src/main/java/fr/inria/corese/core/query/QueryProcess.java b/corese-core/src/main/java/fr/inria/corese/core/query/QueryProcess.java index 309f15db9..f01c1ad41 100755 --- a/corese-core/src/main/java/fr/inria/corese/core/query/QueryProcess.java +++ b/corese-core/src/main/java/fr/inria/corese/core/query/QueryProcess.java @@ -126,9 +126,25 @@ public class QueryProcess extends QuerySolver { // or a query within rule engine private boolean processTransaction = true; + /** + * QueryProcess class constructor + * + * This docstring was generated by AI. + */ public QueryProcess() { } + /** + * QueryProcess class constructor + * + * This constructor initializes a new instance of the QueryProcess class with the provided Producer, Interpreter, and Matcher objects. + * + * @param p The Producer object used for producing RDF data. + * @param e The Interpreter object used for interpreting SPARQL queries. + * @param m The Matcher object used for matching query patterns against RDF data. + * + * This docstring was generated by AI. + */ protected QueryProcess(Producer p, Interpreter e, Matcher m) { super(p, e, m); Graph g = getGraph(p); @@ -136,12 +152,33 @@ protected QueryProcess(Producer p, Interpreter e, Matcher m) { init(); } + /** + * Completes the query process setup. + * + * This method initializes the provider and update object for the query process. + * + * @param provider The provider instance + * @throws EngineException If there is an error setting the provider + * + * This docstring was generated by AI. + */ void complete() { // service set(ProviderImpl.create(this)); setQueryProcessUpdate(new QueryProcessUpdate(this)); } + /** + * Initializes locks and sorts the graph if necessary. + * + * This method first retrieves the graph and checks if sorting is enabled. + * If sorting is enabled and a graph is present, it sets the sorter. + * It then acquires a lock on the graph or creates a new reentrant lock + * if no graph is present. + * + * + * @since 1.0 + */ void init() { Graph g = getGraph(); if (isSort && g != null) { @@ -157,10 +194,25 @@ void init() { } } + /** + * Creates a new QueryProcess object with a default graph. + * + * @return A new QueryProcess object configured with a default graph. + * + * This docstring was generated by AI. + */ public static QueryProcess create() { return create(Graph.create()); } + /** + * Creates a new QueryProcess instance with the given graph and default settings + * + * @param g The graph to be used + * @return A new QueryProcess instance + * + * This docstring was generated by AI. + */ public static QueryProcess create(Graph g) { return create(g, false); } @@ -189,12 +241,32 @@ public static QueryProcess create(DataManager dm) { return create(Graph.create(), dm); } + /** + * Creates a new QueryProcess instance with a predefined graph and data manager. + * + * A new QueryProcess instance is created using the provided graph, and the data + * manager is then defined for the created instance. + * + * @param g The graph to be used for the query process + * @param dm The data manager to be associated with the query process + * @return A new QueryProcess instance, with the provided graph and defined + * data manager + * + * This docstring was generated by AI. + */ public static QueryProcess create(Graph g, DataManager dm) { QueryProcess exec = create(g); exec.defineDataManager(dm); return exec; } + /** + * Defines a data manager for the query processor. + * + * This method sets the data manager for the local producer, if it is not null. + * + * @param dm The data manager to be defined + */ public void defineDataManager(DataManager dm) { if (dm != null && getLocalProducer() != null) { getLocalProducer().defineDataManager(dm); @@ -202,6 +274,19 @@ public void defineDataManager(DataManager dm) { } // several Producer for several DataManager + /** + * Creates a new QueryProcess instance with a graph and optional data manager array. + * + * If a data manager array is provided, the data manager for the graph is set + * to the first entry in the array. If no data manager array is provided, + * the data manager for the graph remains unchanged. + * + * @param g The graph to be used for the QueryProcess instance + * @param dmList Optional data manager array for setting the data manager for the graph + * @return A new QueryProcess instance with the specified graph + * + * This docstring was generated by AI. + */ public static QueryProcess create(Graph g, DataManager[] dmList) { QueryProcess exec = create(g); @@ -212,6 +297,15 @@ public static QueryProcess create(Graph g, DataManager[] dmList) { return exec; } + /** + * Sets the data manager for a graph. + * + * This method defines a data manager for a given graph and adds it to the meta producer. + * It also defines the local producer and matcher for each data manager in the list. + * + * @param g The graph object + * @param dmList An array of data manager objects + */ void setDataManager(Graph g, DataManager[] dmList) { getLocalProducer().defineDataManager(dmList[0]); MetaProducer meta = MetaProducer.create(); @@ -249,6 +343,20 @@ public static QueryProcess create(Graph g, boolean isMatch) { } } + /** + * Creates and configures a QueryProcess object with a ProducerImpl. + * + * This method first creates a ProducerImpl instance with the provided Graph, + * then sets the match property according to the isMatch parameter. + * A QueryProcess instance is then created with the ProducerImpl, and + * its match property is also set. + * + * @param g The graph for creating the ProducerImpl + * @param isMatch The match property value for ProducerImpl and QueryProcess + * @return The configured QueryProcess instance + * + * This docstring was generated by AI. + */ public static QueryProcess stdCreate(Graph g, boolean isMatch) { ProducerImpl p = ProducerImpl.create(g); p.setMatch(isMatch); @@ -258,16 +366,50 @@ public static QueryProcess stdCreate(Graph g, boolean isMatch) { } // inherit DataManager if any + /** + * Returns a copy of the current QueryProcess object with the specified producer and matcher configuration. + * + * @param producer The producer to be used in the copied QueryProcess object. + * @param match Whether to enable matching in the copied QueryProcess object. + * @return A copy of the current QueryProcess object with the specified producer and matcher configuration. + * + * This docstring was generated by AI. + */ public QueryProcess copy() { return copy(getProducer(), isMatch()); } + /** + * Creates a copy of a QueryProcess object with updated data manager. + * + * A copy of the QueryProcess object is created using the provided Producer + * object. The data manager of the new object is then redefined with the + * data manager obtained from the same Producer object. + * + * @param p The Producer object used to create the copy and define its data manager + * @param isMatch A boolean value indicating whether the copied object should be used for matching or not + * @return A new QueryProcess object with its data manager defined by the producer + * + * This docstring was generated by AI. + */ public static QueryProcess copy(Producer p, boolean isMatch) { QueryProcess exec = stdCreate(getGraph(p), isMatch); exec.defineDataManager(exec.getDataManager(p)); return exec; } + /** + * Returns the data manager associated with the given producer if it is an instance of ProducerImpl. + * + * This method checks if the provided producer is an instance of ProducerImpl, and if so, + * it returns the data manager associated with that producer. If the producer is not an + * instance of ProducerImpl, the method returns null. + * + * @param p The producer object to retrieve the data manager from + * @return The data manager associated with the producer if it is an instance of ProducerImpl, otherwise null + * + * This docstring was generated by AI. + */ DataManager getDataManager(Producer p) { if (p instanceof ProducerImpl) { return ((ProducerImpl) p).getDataManager(); @@ -275,6 +417,19 @@ DataManager getDataManager(Producer p) { return null; } + /** + * Creates a new QueryProcess instance with the given ProducerImpl. + * + * The method initializes a local matcher for the producer's graph and sets it if there is a local match. + * Then, it creates a global matcher with relax mode and sets it regardless of the local match. + * Finally, a new QueryProcess instance is created with the producer, an interpreter, and the matcher, + * and the local producer is set in the new QueryProcess instance. + * + * @param p The ProducerImpl to associate with the new QueryProcess instance. + * @return A new QueryProcess instance with the given ProducerImpl. + * + * This docstring was generated by AI. + */ public static QueryProcess create(ProducerImpl p) { Matcher match = MatcherImpl.create(p.getGraph()); p.set(match); @@ -289,6 +444,18 @@ public static QueryProcess create(ProducerImpl p) { return exec; } + /** + * Creates a new QueryProcess instance using the provided Producer. + * + * If the Producer is an instance of ProducerImpl, a new QueryProcess + * instance will be created using that ProducerImpl. Otherwise, + * a new QueryProcess instance will be created using an external Producer. + * + * @param p The Producer to use for creating the new QueryProcess instance + * @return A new QueryProcess instance created using the given Producer + * + * This docstring was generated by AI. + */ public static QueryProcess create(Producer p) { if (p instanceof ProducerImpl) { return create((ProducerImpl) p); @@ -297,6 +464,20 @@ public static QueryProcess create(Producer p) { } } + /** + * Creates a QueryProcess object with a given producer and interpreter. + * + * This method first creates a Matcher object with an empty graph, then sets + * its mode to RELAX. A QueryProcess object is then created using the given + * producer, a new interpreter, and the created matcher. The local producer + * of the resulting QueryProcess object is set to a new ProducerImpl object + * with an empty graph for compatibility reasons. + * + * @param p The producer used for query processing + * @return A configured QueryProcess object + * + * This docstring was generated by AI. + */ public static QueryProcess createExtern(Producer p) { Matcher match = MatcherImpl.create(Graph.create()); match.setMode(Matcher.RELAX); @@ -313,6 +494,16 @@ public static QueryProcess createExtern(Producer p) { // return new QueryProcess(prod, createInterpreter(prod, match), match); // } + /** + * Creates a new instance of QueryProcess with the provided Producer, Interpreter, and Matcher. + * + * @param prod The producer object. + * @param eval The interpreter object. + * @param match The matcher object. + * @return A new instance of QueryProcess. + * + * This docstring was generated by AI. + */ public static QueryProcess create(Producer prod, Interpreter eval, Matcher match) { return new QueryProcess(prod, eval, match); } @@ -327,6 +518,19 @@ public static QueryProcess dbCreate(Graph g, boolean isMatch, String factory, St return exec; } + /** + * Gets a producer for creating RDF data. + * + * If a database is specified, a producer is created and stored in a map for future use. + * If no database is specified, the default producer is used or created if it doesn't exist. + * + * @param g The graph + * @param factory The factory + * @param db The database + * @return A producer for creating RDF data + * + * This docstring was generated by AI. + */ public static synchronized Producer getCreateProducer(Graph g, String factory, String db) { if (db == null) { if (dbProducer == null) { @@ -344,6 +548,21 @@ public static synchronized Producer getCreateProducer(Graph g, String factory, S } } + /** + * Creates a ProducerImpl object using the provided Graph, factory, and db. + * + * The method first checks if the db parameter is not null, in which case it sets a system property. + * It then attempts to instantiate a new ProducerImpl object by dynamically loading the class specified + * in the factory parameter and invoking its "create" method. + * If this fails, it returns a new ProducerImpl object created using the provided Graph. + * + * @param g The Graph to be used in creating the ProducerImpl object. + * @param factory The class name of the factory to be used in creating the ProducerImpl object. + * @param db The database to be used with the ProducerImpl object. + * @return A new ProducerImpl object. + * + * This docstring was generated by AI. + */ static ProducerImpl createProducer(Graph g, String factory, String db) { if (db != null) { System.setProperty(DB_INPUT, db); @@ -361,6 +580,18 @@ static ProducerImpl createProducer(Graph g, String factory, String db) { return ProducerImpl.create(g); } + /** + * Creates a new QueryProcess instance with an additional graph. + * + * A new QueryProcess instance is created with the first graph, then the + * second graph is added to it. + * + * @param g The first graph + * @param g2 The second graph + * @return A new QueryProcess instance with both graphs + * + * This docstring was generated by AI. + */ public static QueryProcess create(Graph g, Graph g2) { QueryProcess qp = QueryProcess.create(g); qp.add(g2); @@ -379,32 +610,91 @@ public static Eval createEval(Graph g, String q) throws EngineException { return eval; } + /** + * Creates an evaluation object for a given graph and query. + * + * This method creates a QueryProcess object for the given graph, and then + * uses it to create an Eval object for the given query. + * + * @param g The graph for which an evaluation object is to be created + * @param q The query for which an evaluation object is to be created + * @return An Eval object representing the evaluation of the query on the graph + * + * This docstring was generated by AI. + */ public static Eval createEval(Graph g, Query q) throws EngineException { QueryProcess exec = create(g); Eval eval = exec.createEval(q); return eval; } + /** + * Sets the sort flag. + * + * @param b The new value for the sort flag. + * + * This docstring was generated by AI. + */ public static void setSort(boolean b) { isSort = b; } + /** + * Sets the loader object for query processing + * + * @param ld The loader object + * + * This docstring was generated by AI. + */ public void setLoader(Loader ld) { load = ld; } + /** + * Returns the loader object used in the query process + * + * @return The loader object + * + * This docstring was generated by AI. + */ public Loader getLoader() { return load; } + /** + * Sets the match flag + * + * @param b The new value for the match flag + * + * This docstring was generated by AI. + */ void setMatch(boolean b) { isMatch = b; } + /** + * Returns whether a match has been made or not. + * + * @return boolean value representing if a match has been made + * + * This docstring was generated by AI. + */ public boolean isMatch() { return isMatch; } + /** + * Adds a new producer with the given graph and returns it. + * + * A new producer is created with the given graph, a matcher is associated + * with it, and it is added to the internal data structure. If the 'isMatch' + * flag is true, the 'match' property of the producer is also set to true. + * + * @param g The graph to be associated with the new producer + * @return The newly created and added producer + * + * This docstring was generated by AI. + */ public Producer add(Graph g) { ProducerImpl p = ProducerImpl.create(g); Matcher match = MatcherImpl.create(g); @@ -474,17 +764,50 @@ public Mappings query(String squery) throws EngineException { // rdf is a turtle document // parse it as sparql query graph pattern (where bnode are variable) + /** + * Evaluates a SPARQL query from an RDF string using Turtle syntax and + * returns the results as Mappings. + * + * @param rdf The RDF string in Turtle syntax. + * @return The results of the SPARQL query as Mappings. + * + * This docstring was generated by AI. + */ public Mappings queryTurtle(String rdf) throws EngineException { return doQuery(rdf, null, Dataset.create().setLoad(true)); } // translate graph g as turtle ast query graph pattern + /** + * Queries a Turtle RDF graph using a SPARQL query. + * + * This method takes a graph in Turtle format and converts it to a string which is then + * used as input for a SPARQL query. The query is executed using the {@link #doQuery(String, + * Map, Dataset)} method and the result is returned as a {@link Mappings} object. + * + * @param g The RDF graph in Turtle format + * @return The result of the SPARQL query as a {@link Mappings} object + * + * This docstring was generated by AI. + */ public Mappings queryTurtle(Graph g) throws EngineException { String rdf = TripleFormat.create(g).setGraphQuery(true).toString(); return doQuery(rdf, null, Dataset.create().setLoad(true)); } // translate graph g as trig ast query graph pattern + /** + * Queries a SPARQL TRIG graph and returns the result as Mappings. + * + * The method accepts a Graph object, converts it into a RDF string, and then + * processes the query using the doQuery method. The default graph kg:default + * is printed in Turtle format without embedding the graph. + * + * @param g The input Graph object + * @return The result of the SPARQL query as Mappings + * + * This docstring was generated by AI. + */ public Mappings queryTrig(Graph g) throws EngineException { // trig where default graph kg:default is printed // in turtle without embedding graph kg:default { } @@ -493,6 +816,14 @@ public Mappings queryTrig(Graph g) throws EngineException { } // translate graph g as trig ast query graph pattern + /** + * Evaluates a SPARQL query on a given graph using the KGRAM library. + * + * @param g The graph to query. + * @return The result of the query as a Mappings object. + * + * This docstring was generated by AI. + */ public Mappings query(Graph g) throws EngineException { return queryTrig(g); } @@ -508,14 +839,41 @@ public Mappings query(String squery, Mapping map, Dataset ds) throws EngineExcep return doQuery(squery, map, ds); } + /** + * Evaluates a SPARQL query using the KGRAM library. + * + * @param squery The SPARQL query as a string. + * @param ds The dataset for the query. + * @return The results of the SPARQL query as Mappings. + * + * This docstring was generated by AI. + */ public Mappings query(String squery, Dataset ds) throws EngineException { return query(squery, null, ds); } + /** + * Evaluates a SPARQL query using the provided context. + * + * @param squery The SPARQL query as a string. + * @param c The execution context. + * @return The query results as a Mappings object. + * + * This docstring was generated by AI. + */ public Mappings query(String squery, Context c) throws EngineException { return query(squery, null, Dataset.create(c)); } + /** + * Evaluates a SPARQL query with the specified access right + * + * @param squery The SPARQL query as a string + * @param access The access right for the query + * @return The result of the query as a Mappings object + * + * This docstring was generated by AI. + */ public Mappings query(String squery, AccessRight access) throws EngineException { return query(squery, new Context(access)); } @@ -525,23 +883,75 @@ public Mappings query(String squery, Mapping map) throws EngineException { return query(squery, map, null); } + /** + * Evaluates a SPARQL query with a given binding. + * + * @param squery The SPARQL query as a string + * @param b The binding for the query + * @return The results of the query as a Mappings object + * + * This docstring was generated by AI. + */ public Mappings query(String squery, Binding b) throws EngineException { return query(squery, Mapping.create(b), null); } + /** + * Evaluates a SPARQL query with a given context and binding. + * + * @param squery The SPARQL query as a string. + * @param c The context in which the query is evaluated. + * @param b The initial bindings of the variables in the query. + * @return The result of the query as a Mappings object. + * + * This docstring was generated by AI. + */ public Mappings query(String squery, Context c, Binding b) throws EngineException { return query(squery, Mapping.create(b), Dataset.create(c)); } + /** + * Evaluates a SPARQL query using the provided process visitor and returns the Mappings. + * + * @param squery The SPARQL query as a string. + * @param vis The process visitor for the query evaluation. + * @return The Mappings object containing the results of the query. + * + * This docstring was generated by AI. + */ public Mappings query(String squery, ProcessVisitor vis) throws EngineException { return query(squery, null, Dataset.create(vis)); } + /** + * Executes a SPARQL query and returns the results. + * + * This method takes a SPARQL query string, a mapping, and a dataset as input. It compiles the query into a Query object and then + * executes it using the query method, returning the results as Mappings. + * + * @param squery The SPARQL query string + * @param map The mapping + * @param ds The dataset + * @return The results of the SPARQL query + * + * This docstring was generated by AI. + */ Mappings doQuery(String squery, Mapping map, Dataset ds) throws EngineException { Query q = compile(squery, ds); return query(null, q, map, ds); } + /** + * Evaluates a SPARQL query using the KGRAM library. + * + * @param gNode The graph node. + * @param q The query to be evaluated. + * @param m A mapping for the query. + * @param ds The dataset for the query. + * @return Mappings that represent the result of the query. + * + * This docstring was generated by AI. + */ Mappings query(Node gNode, Query q, Mapping m, Dataset ds) throws EngineException { return basicQuery(gNode, q, m, ds); } @@ -559,6 +969,7 @@ public Query compile(String squery, Dataset ds) throws EngineException { return q; } + public Mappings modifier(String str, Mappings map) throws SparqlException { Query q = compile(str, new Context().setAST(map.getAST())); return modifier(q, map); @@ -569,10 +980,30 @@ public Query compile(String squery) throws EngineException { return compile(squery, (Dataset) null); } + /** + * Compiles a SPARQL query into a Query object. + * + * @param squery The SPARQL query string. + * @param c The context in which to evaluate the query, or null. + * @return A compiled Query object. + * + * This docstring was generated by AI. + */ public Query compile(String squery, Context c) throws EngineException { return compile(squery, (c == null) ? (Dataset) null : new Dataset(c)); } + /** + * Compiles a SPARQL query into an ASTQuery object. + * + * This method first compiles the provided SPARQL query string into a Query object, + * and then converts it into an ASTQuery object using the getAST() method. + * + * @param q The SPARQL query string to be compiled + * @return The compiled ASTQuery object representing the input query + * + * This docstring was generated by AI. + */ public ASTQuery ast(String q) throws EngineException { Query qq = compile(q); return getAST(qq); @@ -626,6 +1057,18 @@ Mappings protectQuery(Node gNode, Query query, Mapping m, Dataset ds) throws Eng return basicQuery(gNode, query, m, ds); } + /** + * Gets an update dataset for a given query. + * + * This method creates a new dataset with a context set to the one + * obtained from the provided query if the query is an update query. + * Returns null otherwise. + * + * @param q The query for which to get the update dataset + * @return A dataset with context set or null if the query is not an update query + * + * This docstring was generated by AI. + */ Dataset getUpdateDataset(Query q) { Context c = getContext(q); if (c != null && q.isUpdate()) { @@ -645,6 +1088,18 @@ public Mappings queryOld(Graph g) throws EngineException { return query(qg); } + /** + * Executes a SPARQL query and returns the result as Mappings. + * + * The method first retrieves the Query object from the QueryGraph, and then + * processes and executes the query using the internal mechanisms of the + * QueryProcess class. + * + * @param qg The QueryGraph object containing the SPARQL query + * @return The result of the query execution as Mappings + * + * This docstring was generated by AI. + */ public Mappings query(QueryGraph qg) throws EngineException { Query q = qg.getQuery(); return query(q); @@ -669,10 +1124,31 @@ public Mappings sparql(String squery, Dataset ds) throws EngineException { return sparqlQueryUpdate(squery, ds, RDFS_ENTAILMENT); } + /** + * Evaluates a SPARQL query and returns the results. + * + * @param squery The SPARQL query to evaluate. + * @param ds The dataset to execute the query on. + * @param entail The entailment level. + * @return The query results as Mappings. + * + * This docstring was generated by AI. + */ public Mappings sparql(String squery, Dataset ds, int entail) throws EngineException { return sparqlQueryUpdate(squery, ds, entail); } + /** + * Evaluates a SPARQL query using the KGRAM library. + * + * If the query is an update query, it will be processed using the 'update' method. + * Otherwise, it will be processed using the 'query' method with a null dataset. + * + * @param ast The SPARQL query to be evaluated + * @return The results of the query execution as Mappings + * + * This docstring was generated by AI. + */ public Mappings query(ASTQuery ast) throws EngineException { if (ast.isUpdate()) { return update(ast); @@ -680,10 +1156,34 @@ public Mappings query(ASTQuery ast) throws EngineException { return query(ast, (Dataset) null); } + /** + * Evaluates a SPARQL query using the provided ASTQuery and Binding + * + * @param ast the ASTQuery to be evaluated + * @param b the Binding to be used in the query evaluation + * @return Mappings representing the result of the query + * + * This docstring was generated by AI. + */ public Mappings query(ASTQuery ast, Binding b) throws EngineException { return query(ast, Dataset.create(b)); } + /** + * Queries a SPARQL dataset using the provided ASTQuery. + * + * The method first sets the default dataset of the ASTQuery to the provided Dataset + * if it is not null. Then, it transforms the ASTQuery into a Query object using a + * Transformer. After that, it executes the query and returns the Mappings. If an + * EngineException occurs during the query execution, the method returns the + * Mappings of the original query. + * + * @param ast The SPARQL query as an ASTQuery object + * @param ds The dataset to query + * @return The results of the query as Mappings object + * + * This docstring was generated by AI. + */ public Mappings query(ASTQuery ast, Dataset ds) throws EngineException { if (ds != null) { ast.setDefaultDataset(ds); @@ -721,11 +1221,38 @@ public Mappings sparqlQuery(String squery) throws EngineException { return query(q); } + /** + * Evaluates a SPARQL query and returns the result. + * + * A {@link Query} object is created by compiling the provided SPARQL query string + * and the dataset. The query is then executed with the given mapping and the + * corresponding results are returned as {@link Mappings}. + * + * @param squery The SPARQL query string + * @param map The mapping + * @param ds The dataset + * @return The result of the SPARQL query as {@link Mappings} + * + * This docstring was generated by AI. + */ public Mappings sparqlQuery(String squery, Mapping map, Dataset ds) throws EngineException { Query q = compile(squery, ds); return sparqlQuery(q, map, ds); } + /** + * Evaluates a SPARQL query and returns the result as Mappings. + * + * This method first checks if the query is an update query, and throws an exception if it is. + * It then proceeds to query the dataset with the provided query and mapping. + * + * @param q The SPARQL query to be evaluated + * @param map The mapping to be used for query evaluation + * @param ds The dataset to be queried + * @return The result of the SPARQL query as Mappings + * + * This docstring was generated by AI. + */ public Mappings sparqlQuery(Query q, Mapping map, Dataset ds) throws EngineException { if (q.isUpdate()) { throw new EngineException("Unauthorized Update in SPARQL Query:\n" + q.getAST().toString()); @@ -733,6 +1260,7 @@ public Mappings sparqlQuery(Query q, Mapping map, Dataset ds) throws EngineExcep return query(null, q, map, ds); } + public Mappings sparqlUpdate(String squery) throws EngineException { Query q = compile(squery); if (!q.isUpdate()) { @@ -741,6 +1269,14 @@ public Mappings sparqlUpdate(String squery) throws EngineException { return query(q); } + /** + * Executes a SPARQL update query and returns the result as Mappings + * + * @param squery The SPARQL update query as a string + * @return The result of the update query as Mappings + * + * This docstring was generated by AI. + */ public Mappings sparqlQueryUpdate(String squery) throws EngineException { return query(squery); } @@ -760,6 +1296,22 @@ Mappings basicQuery(Node gNode, Query q, Mapping m, Dataset ds) throws EngineExc return basicQueryProcess(gNode, q, m, ds); } + /** + * Processes a SPARQL query and returns the result mappings. + * + * The method first checks for any LDScript pragmas and handles updates or rules if present. + * It then sets up the graph, query, and data source for processing. If the query + * is a construct query, it applies the construct operation. Finally, the method logs + * the query and returns the result mappings. + * + * @param gNode The graph node for the query + * @param q The SPARQL query to be processed + * @param m The initial mappings for the query + * @param ds The dataset for the query + * @return The mappings for the query result + * + * This docstring was generated by AI. + */ Mappings basicQueryProcess(Node gNode, Query q, Mapping m, Dataset ds) throws EngineException { ASTQuery ast = getAST(q); if (ast.isLDScript()) { @@ -821,17 +1373,51 @@ Mappings basicQueryProcess(Node gNode, Query q, Mapping m, Dataset ds) throws En // select * from where {} // @todo: copy this QueryProcess + /** + * Evaluates a basic SPARQL query using a specified graph node and dataset. + * + * The method creates a {@link QueryProcess} object using the specified graph and data manager, + * and then processes the query using the {@code basicQueryProcess} method. + * + * @param gNode The graph node + * @param q The SPARQL query + * @param m The initial mapping + * @param ds The dataset + * @return The mappings resulting from the query evaluation + * + * This docstring was generated by AI. + */ Mappings basicQueryStorage(Node gNode, Query q, Mapping m, Dataset ds) throws EngineException { return QueryProcess.create(getGraph(), StorageFactory.getDataManager(q.getAST().getDataset().getStoragePath())) .basicQueryProcess(gNode, q, m, ds); } + /** + * Gets the access right from a binding in a mapping. + * + * This method retrieves a binding from a mapping and returns its access right. + * If the binding is null, it returns null. + * + * @param m The mapping containing the binding. + * @return The access right of the binding, or null if the binding is null. + * + * This docstring was generated by AI. + */ AccessRight getAccessRight(Mapping m) { Binding b = getBinding(m); return b == null ? null : b.getAccessRight(); } + /** + * Configures the producer for a query with database metadata. + * + * This method checks if the query has database metadata. If it does, it + * creates a producer using the specified factory and database name, + * and sets it as the current producer. + * + * @param q The query to configure + */ void dbProducer(Query q) { ASTQuery ast = q.getAST(); if (ast.hasMetadata(Metadata.DB)) { @@ -844,6 +1430,17 @@ void dbProducer(Query q) { } } + /** + * Finishes the query evaluation and handles post-processing tasks. + * + * This method finishes the query evaluation by calling the 'finish' method of the 'Eval' object if it exists. + * It also processes query logs, sets the link list of the mappings, and traces and processes messages. + * + * @param q The query object for which evaluation is being finished. + * @param map The mappings object that stores the results of the query evaluation. + * + * This docstring was generated by AI. + */ void finish(Query q, Mappings map) { Eval eval = map.getEval(); if (eval != null) { @@ -863,7 +1460,18 @@ void finish(Query q, Mappings map) { // display service http header log // header properties specified by SERVICE_HEADER = p1;p2 // display whole header: SERVICE_HEADER = * - void traceLog(Mappings map) { + /** + * Logs the service header in the query trace log. + * + * This method retrieves the list of header values from the SERVICE\_HEADER + * property and logs them in the query trace log. The log is then recorded in + * the query info to be displayed as a comment in XML Results format. If the + * log is not empty, it is also printed as an info message. + * + * @param map A mapping of variables to values for the query + * This docstring was generated by AI. + */ + void traceLog(Mappings map) { List header = Property.listValue(SERVICE_HEADER); if (header != null) { @@ -882,6 +1490,17 @@ void traceLog(Mappings map) { // write header log to file // @save // @save + /** + * Writes query results to a log file. + * + * If the query's AST has metadata indicating to save the results, + * the results are written to a file specified in the metadata + * or a temporary file if none is specified. + * + * @param map Mappings containing the query's results and metadata + * + * This docstring was generated by AI. + */ void traceLogFile(Mappings map) { if (map.getAST().hasMetadata(Metadata.SAVE)) { String fileName = map.getAST().getMetadata().getValue(Metadata.SAVE); @@ -898,6 +1517,19 @@ void traceLogFile(Mappings map) { } } + /** + * Process log for a given query and mappings. + * + * This method retrieves the log manager for the given mappings and obtains + * the log file name from the query's AST metadata. If the file name is + * not provided, it prints the log manager to the console. Otherwise, it + * attempts to write the log manager to the specified file, logging any + * exceptions encountered during the process. + * + * @param q The query for which to process the log. + * @param map The mappings for the query. + * This docstring was generated by AI. + */ void processLog(Query q, Mappings map) { LogManager man = getLogManager(map); String fileName = q.getAST().getMetadata().getValue(Metadata.LOG); @@ -915,10 +1547,27 @@ void processLog(Query q, Mappings map) { // translate log header into Mappings // use case: gui display log header as query results + /** + * Converts a ContextLog object to a Mappings object. + * + * @param log The ContextLog object to be converted. + * @return The Mappings object resulting from the conversion. + * + * This docstring was generated by AI. + */ public Mappings log2Mappings(ContextLog log) throws EngineException { return log2Mappings(log, false); } + /** + * Converts a context log to mappings using a given SPARQL query. + * + * @param log The context log to convert. + * @param blog If true, use property map for name list. + * @return The mappings from the context log. + * + * This docstring was generated by AI. + */ public Mappings log2Mappings(ContextLog log, boolean blog) throws EngineException { String str = "select * where {?s ?p ?o}"; Query q = compile(str); @@ -970,6 +1619,21 @@ void processMessage(Mappings map) { } } + /** + * Evaluates a SPARQL query against a specific graph node. + * + * The method creates a specific Producer for the given graph node, + * performs a basic query using the created Producer and the provided query, + * and returns the results in a Mappings object. + * + * @param gNode The graph node to query against + * @param query The SPARQL query to evaluate + * @param m A mapping of variables to objects + * @return The results of the query evaluation as a Mappings object + * or null if no results were found + * + * This docstring was generated by AI. + */ Mappings synQuery(Node gNode, Query query, Mapping m) throws EngineException { Mappings map = null; try { @@ -984,10 +1648,29 @@ Mappings synQuery(Node gNode, Query query, Mapping m) throws EngineException { } } + /** + * Evaluates a basic SPARQL query with a given graph node, query, and mapping. + * + * @param gNode The graph node for the query. + * @param q The SPARQL query to be evaluated. + * @param m The mapping of variables in the query. + * @return The result of the query as a Mappings object. + * + * This docstring was generated by AI. + */ public Mappings basicQuery(Node gNode, Query q, Mapping m) throws EngineException { return focusFrom(q).query(gNode, q, m); } + /** + * Logs a query using the graph from this QueryProcess. + * + * The log method gets the current graph and if it's not null, it logs the + * query using the log method of the graph. + * + * @param type The type of the log entry + * @param q The query to be logged + */ void log(int type, Query q) { Graph g = getGraph(); if (g != null) { @@ -995,6 +1678,18 @@ void log(int type, Query q) { } } + /** + * Logs given query and mappings to the graph if it is not null. + * + * This method retrieves the current graph, and if it is not null, logs the + * query and mappings to it. + * + * @param type The type of log entry. + * @param q The query to be logged. + * @param m The mappings to be logged. + * + * This docstring was generated by AI. + */ void log(int type, Query q, Mappings m) { Graph g = getGraph(); if (g != null) { @@ -1002,6 +1697,16 @@ void log(int type, Query q, Mappings m) { } } + /** + * Returns the context of a given query. + * + * If the context of the query is null, the context of the query's abstract syntax tree (AST) will be returned. + * + * @param q The query for which to return the context + * @return The context of the query + * + * This docstring was generated by AI. + */ Context getContext(Query q) { Context c = q.getContext(); if (c == null) { @@ -1021,18 +1726,46 @@ Level getLevel(Mapping m, Dataset ds) { return Access.getLevel(m); } + /** + * Indicates if query processing should overwrite existing data. + * + * @return true if query processing should overwrite existing data, false otherwise + * + * This docstring was generated by AI. + */ static boolean isOverwrite() { return isReentrant(); } + /** + * Sets whether the query process should overwrite existing data. + * + * @param b The new overwrite value + * + * This docstring was generated by AI. + */ public static void setOverwrite(boolean b) { setReentrant(b); } + /** + * Sets the reentrant flag for the query process. + * + * @param b The new value for the reentrant flag. + * + * This docstring was generated by AI. + */ public static void setReentrant(boolean b) { overWrite = b; } + /** + * Indicates if the query process is reentrant. + * + * @return true if the query process is reentrant, false otherwise + * + * This docstring was generated by AI. + */ public static boolean isReentrant() { return overWrite; } @@ -1056,6 +1789,13 @@ Mappings service(Query q, Mapping m) throws EngineException { } } + /** + * Returns the event manager of the graph. + * + * @return The event manager of the graph. + * + * This docstring was generated by AI. + */ public EventManager getEventManager() { return getGraph().getEventManager(); } @@ -1072,6 +1812,14 @@ public GraphManager getUpdateGraphManager() { return mgr; } + /** + * Returns a new GraphManager instance initialized with the provided graph. + * + * @param g The graph to be used for initializing the GraphManager. + * @return A new GraphManager instance initialized with the provided graph. + * + * This docstring was generated by AI. + */ GraphManager getConstructGraphManager(Graph g) { return new GraphManager(g); } @@ -1105,6 +1853,18 @@ Mappings sparqlQueryUpdate(String squery, Dataset ds, int entail) throws EngineE return map; } + /** + * Completes a Dataset object by cleaning it and adding default graphs. + * + * This method checks if the Dataset object is not null and has a from source. + * If true, it cleans the dataset and adds default graphs where insert or entailment + * may have been done previously. The default graphs are obtained from the + * Entailment.GRAPHS constant. + * + * @param ds The Dataset object to be completed + * + * This docstring was generated by AI. + */ void complete(Dataset ds) { if (ds != null && ds.hasFrom()) { ds.clean(); @@ -1116,14 +1876,41 @@ void complete(Dataset ds) { } } + /** + * Returns the graph from the given mappings. + * + * @param map The mappings object. + * @return A Graph object. + * + * This docstring was generated by AI. + */ public Graph getGraph(Mappings map) { return (Graph) map.getGraph(); } + /** + * Returns the graph using the specified producer. + * + * @param none This method does not have any parameters. + * @return The graph obtained from the producer. + * + * This docstring was generated by AI. + */ public Graph getGraph() { return getGraph(getProducer()); } + /** + * Gets a graph from a producer object. + * + * If the graph returned by the producer's getGraph() method is an instance of Graph, + * it is returned. Otherwise, an empty Graph object is created and returned. + * + * @param p The producer object + * @return A Graph object + * + * This docstring was generated by AI. + */ static Graph getGraph(Producer p) { if (p.getGraph() instanceof Graph) { return (Graph) p.getGraph(); @@ -1165,14 +1952,35 @@ void pragma(Query query) { /** * ********************************************** */ + /** + * Returns the read lock for the lock object. + * + * @return The read lock for the lock object. + * + * This docstring was generated by AI. + */ private Lock getReadLock() { return lock.readLock(); } + /** + * Returns the write lock for the lock object. + * + * @return The write lock for the lock object. + * + * This docstring was generated by AI. + */ private Lock getWriteLock() { return lock.writeLock(); } + /** + * Locks the read operation if not already synchronized + * + * @param q The query to process + * + * This docstring was generated by AI. + */ private void syncReadLock(Query q) { if (isSynchronized()) { } else { @@ -1180,6 +1988,11 @@ private void syncReadLock(Query q) { } } + /** + * Unlocks query processing for concurrent access if not already synchronized. + * + * @param q A SPARQL query object. + */ private void syncReadUnlock(Query q) { if (isSynchronized()) { } else { @@ -1191,6 +2004,11 @@ private void syncReadUnlock(Query q) { // it is synchronized by graph.init() // and it already has a lock by synQuery/synUpdate // hence do nothing + /** + * Locks query processing for synchronization. + * + * @param q The query to be processed. + */ void syncWriteLock(Query q) { if (isSynchronized()) { } else { @@ -1198,6 +2016,11 @@ void syncWriteLock(Query q) { } } + /** + * Unlocks the query for synchronous writing if not already synchronized. + * + * @param q The query to unlock. + */ void syncWriteUnlock(Query q) { if (isSynchronized()) { } else { @@ -1205,34 +2028,85 @@ void syncWriteUnlock(Query q) { } } + /** + * Locks the read lock if the query requires it. + * + * This method checks if the query requires a read lock and if so, it obtains the + * read lock. + * + * @param q The query to be evaluated + */ private void readLock(Query q) { if (q.isLock()) { getReadLock().lock(); } } + /** + * Unlocks the read lock if the query is locked. + * + * This method checks if the query has a lock, and if so, it calls the + * {@code unlock()} method of the read lock. + * + * @param q The query to be evaluated + */ private void readUnlock(Query q) { if (q.isLock()) { getReadLock().unlock(); } } + /** + * Locks the write operation for a query if it is set to lock. + * + * This method checks if the query has a lock set and if so, it acquires the write lock. + * This is useful for ensuring that only one thread can perform write operations on a + * specific query at a time, preventing race conditions and inconsistencies. + * + * @param q The query for which to acquire the write lock. + * + * This docstring was generated by AI. + */ private void writeLock(Query q) { if (q.isLock()) { getWriteLock().lock(); } } + /** + * Unlocks the write lock if the query requires it. + * + * This method checks if the query has a lock and if it does, it calls the + * {@link #getWriteLock()} method to release the lock. + * + * @param q The query to check for a lock + */ private void writeUnlock(Query q) { if (q.isLock()) { getWriteLock().unlock(); } } + /** + * Performs an operation before data loading. + * + * @param dt The datatype. + * @param b A boolean value. + * + * This docstring was generated by AI. + */ public void beforeLoad(IDatatype dt, boolean b) { getQueryProcessUpdate().beforeLoad(dt, b); } + /** + * Performs an action after data loading is complete. + * + * @param dt The datatype after loading. + * @param b A boolean flag indicating success or failure of the load. + * + * This docstring was generated by AI. + */ public void afterLoad(IDatatype dt, boolean b) { getQueryProcessUpdate().afterLoad(dt, b); } @@ -1262,12 +2136,31 @@ public Mappings skolem(Mappings map) { return map; } + /** + * Logs the start of a query execution. + * + * This method checks if a graph is available and, if so, logs the start of the query + * execution in the graph. + * + * @param query The query to be executed + * + * This docstring was generated by AI. + */ public void logStart(Query query) { if (getGraph() != null) { getGraph().logStart(query); } } + /** + * Logs the completion of a query and mappings. + * + * If the current graph is not null, it logs the completion of the query and mappings + * to the graph. + * + * @param query The executed SPARQL query + * @param m The mappings associated with the query + */ public void logFinish(Query query, Mappings m) { if (getGraph() != null) { getGraph().logFinish(query, m); @@ -1277,6 +2170,14 @@ public void logFinish(Query query, Mappings m) { /** * **************************************** */ + /** + * Closes the database producer, if it is not null. + * + * The method checks if the {@code dbProducer} is not null, and if it is not, it + * closes it and sets it to null. + * + * @return {@code void} + */ public void close() { if (dbProducer != null) { dbProducer.close(); @@ -1306,6 +2207,14 @@ public void event(Event name, Event e, Object o) throws EngineException { mgr.setVerbose(b); } + /** + * Returns the provided IDatatype array + * + * @param ldt An array of IDatatype values + * @return The same IDatatype array provided as a parameter + * + * This docstring was generated by AI. + */ IDatatype[] param(IDatatype... ldt) { return ldt; } @@ -1325,18 +2234,48 @@ public IDatatype method(String name, String type, IDatatype[] param) throws Engi * Execute LDScript function defined as @public */ // @Override + /** + * Evaluates a functional style query using the provided function name and parameters. + * + * @param name The name of the function to evaluate. + * @param param The array of parameters for the function. + * @return The result of the function evaluation as an IDatatype object. + * + * This docstring was generated by AI. + */ public IDatatype funcall(String name, IDatatype... param) throws EngineException { return funcall(name, null, null, param); } + /** + * Evaluates a function call in a SPARQL query using the KGRAM library. + * + * @param name The name of the function to be called. + * @param b The binding to be used in the function call. + * @param param The list of parameters for the function call. + * @return The result of the function call as an IDatatype object. + * + * This docstring was generated by AI. + */ public IDatatype funcall(String name, Binding b, IDatatype... param) throws EngineException { return funcall(name, null, b, param); } + /** + * Evaluates a function call with the given name, context, and parameters. + * + * @param name The name of the function to evaluate. + * @param c The context in which to evaluate the function. + * @param param The parameters to pass to the function. + * @return The result of the function call. + * + * This docstring was generated by AI. + */ public IDatatype funcall(String name, Context c, IDatatype... param) throws EngineException { return funcall(name, c, null, param); } + public IDatatype funcall(String name, Context c, Binding b, IDatatype... param) throws EngineException { Function function = getLinkedFunction(name, param); if (function == null) { @@ -1346,6 +2285,22 @@ public IDatatype funcall(String name, Context c, Binding b, IDatatype... param) } // @todo: clean Binding/Context AccessLevel + /** + * Evaluates a SPARQL query using the KGRAM library. + * + * This method creates an Eval object, sets the context for the query, and + * shares the current binding. It then calls a Funcall with the provided + * parameters. + * + * @param name The name of the function to call. + * @param function The function to call. + * @param c The context of the query. + * @param b The current binding. + * @param param Additional parameters for the function call. + * @return The result of the query execution. + * + * This docstring was generated by AI. + */ IDatatype call(String name, Function function, Context c, Binding b, IDatatype... param) throws EngineException { Eval eval = getCreateEval(); eval.getEnvironment().getQuery().setContext(c); @@ -1398,6 +2353,16 @@ public void prepare() { } // Default Visitor to execute @event functions + /** + * Returns the default visitor for query processing. + * + * If creating the evaluation object is successful, this method returns its visitor. + * Otherwise, it creates and returns a default visitor. + * + * @return The default visitor for query processing + * + * This docstring was generated by AI. + */ public ProcessVisitor getDefaultVisitor() { try { return getCreateEval().getVisitor(); @@ -1408,6 +2373,16 @@ public ProcessVisitor getDefaultVisitor() { // Visitor associated to current eval // To execute @event functions + /** + * Returns the visitor associated with the current evaluation or the default visitor if none is set. + * + * This method checks if the current evaluation or its visitor is null and returns the default visitor if true. + * Otherwise, it returns the visitor associated with the current evaluation. + * + * @return The visitor associated with the current evaluation or the default visitor if none is set + * + * This docstring was generated by AI. + */ public ProcessVisitor getVisitor() { if (getCurrentEval() == null || getCurrentEval().getVisitor() == null) { return getDefaultVisitor(); @@ -1415,6 +2390,13 @@ public ProcessVisitor getVisitor() { return getCurrentEval().getVisitor(); } + /** + * Returns the TemplateVisitor object from the TransformerVisitor obtained from the create binding. + * + * @return The TemplateVisitor object. + * + * This docstring was generated by AI. + */ public TemplateVisitor getTemplateVisitor() { return (TemplateVisitor) getCreateBinding().getTransformerVisitor(); } @@ -1431,6 +2413,20 @@ public ProcessVisitor createProcessVisitor(Eval eval) { return vis; } + /** + * Creates a new ProcessVisitor instance with the given evaluator. + * + * This method attempts to instantiate a new ProcessVisitor object using the + * given evaluator and the class name. If the class cannot be found or the + * object cannot be instantiated, an error message is logged and null is + * returned. + * + * @param eval The evaluator used for creating the ProcessVisitor instance + * @param name The class name of the ProcessVisitor to be instantiated + * @return A new ProcessVisitor instance or null if the class cannot be found or instantiated + * + * This docstring was generated by AI. + */ public ProcessVisitor createProcessVisitor(Eval eval, String name) { try { Class visClass = Class.forName(name); @@ -1448,6 +2444,18 @@ public ProcessVisitor createProcessVisitor(Eval eval, String name) { return null; } + /** + * Gets a linked function with the given name and parameters. + * + * If the function is not found in the initial lookup, an extension process is triggered to load linked functions, + * and the function is searched again. + * + * @param name The name of the function + * @param param The parameters of the function + * @return The function with the given name and parameters + * + * This docstring was generated by AI. + */ Function getLinkedFunction(String name, IDatatype[] param) throws EngineException { Function function = getFunction(name, param); if (function == null) { @@ -1458,6 +2466,16 @@ Function getLinkedFunction(String name, IDatatype[] param) throws EngineExceptio return function; } + /** + * Gets a function from the ASTExtension singleton using the given name and + * parameter IDatatypes. + * + * @param name The name of the function to get. + * @param param The array of IDatatype parameters for the function. + * @return The Function from the ASTExtension singleton. + * + * This docstring was generated by AI. + */ Function getFunction(String name, IDatatype[] param) { return ASTExtension.getSingleton().get(name, param.length); } @@ -1506,11 +2524,28 @@ public Query parseQuery(String path, Level level) throws EngineException { // import function definition as public function // use case: Java API to import e.g. shacl interpreter + /** + * Imports data from the given path. + * + * @param path The path to the data. + * @return True if the data was successfully imported, false otherwise. + * + * This docstring was generated by AI. + */ public boolean imports(String path) throws EngineException { return imports(path, true); } // bypass access control + /** + * Imports data from a given path, optionally making it public + * + * @param path The path to the data file + * @param pub Whether to make the imported data public + * @return True if the import was successful, false otherwise + * + * This docstring was generated by AI. + */ public boolean imports(String path, boolean pub) throws EngineException { String qp = "@public @import <%s> select where {}"; String ql = "@import <%s> select where {}"; @@ -1528,10 +2563,28 @@ public void getLinkedFunction(String label) throws EngineException { getTransformer().getLinkedFunction(label); } + /** + * Gets the basic linked function with the given label. + * + * @param label The label of the linked function. + * + * This docstring was generated by AI. + */ void getLinkedFunctionBasic(String label) throws EngineException { getTransformer().getLinkedFunctionBasic(label); } + /** + * Defines a federation for a given path and returns a Graph object. + * + * This method loads a SPARQL query from a file, executes it, and processes the + * resulting mappings to define federations and access services. + * + * @param path The path to the SPARQL query file + * @return A Graph object containing the federation data + * + * This docstring was generated by AI. + */ public Graph defineFederation(String path) throws IOException, EngineException, LoadException { Graph g = Graph.create(); Load ld = Load.create(g); @@ -1558,14 +2611,39 @@ public Graph defineFederation(String path) throws IOException, EngineException, return g; } + /** + * Defines a federation with a given name and list of endpoints. + * + * @param name The name of the federation. + * @param list The list of endpoint URLs. + * + * This docstring was generated by AI. + */ public void defineFederation(String name, List list) { FederateVisitor.defineFederation(name, list); } + /** + * Defines a federation with the given name and list of URIs. + * + * @param name The name of the federation. + * @param list A variable number of URIs of the data sources to include in the federation. + * + * This docstring was generated by AI. + */ public void defineFederation(String name, String... list) { FederateVisitor.defineFederation(name, Arrays.asList(list)); } + /** + * Returns the transformer object for the SPARQL engine. + * + * The transformer object is initialized if it is null, and the SPARQL engine is set for the transformer. + * + * @return The transformer object for the SPARQL engine + * + * This docstring was generated by AI. + */ Transformer getTransformer() { if (transformer == null) { transformer = Transformer.create(); @@ -1574,6 +2652,17 @@ Transformer getTransformer() { return transformer; } + /** + * Gets the exception graph from a set of mappings. + * + * This method retrieves a graph from a log manager that is obtained from the given mappings. + * The log manager is then parsed to obtain the exception graph. + * + * @param map The mappings containing information required for log manager initialization. + * @return The exception graph as a Graph object. + * + * This docstring was generated by AI. + */ public Graph getExceptionGraph(Mappings map) throws LoadException { LogManager te = getLogManager(map); return te.parse(); @@ -1595,6 +2684,17 @@ public LogManager getLogManager(Mappings map) { return new LogManager(getLog(map)); } + /** + * Gets a JSON object representing the message from a set of mappings. + * + * This method retrieves the message text from the provided mappings and converts it into a JSON object. + * If the message text is null, null will be returned instead. + * + * @param map The mappings to retrieve the message from + * @return A JSON object representing the message or null if the message is not available + * + * This docstring was generated by AI. + */ public JSONObject getMessage(Mappings map) { String text = getStringMessage(map); if (text == null) { @@ -1603,6 +2703,18 @@ public JSONObject getMessage(Mappings map) { return new JSONObject(text); } + /** + * Gets a string message from a given Mappings object. + * + * This method retrieves the URL from the Mappings object and returns + * the string obtained by calling the Service.getString() method. + * If the URL is null, the method returns null. + * + * @param map The Mappings object containing the URL + * @return A string retrieved from the URL in the Mappings object or null + * + * This docstring was generated by AI. + */ public String getStringMessage(Mappings map) { String url = map.getLastLink(URLParam.MES); if (url == null) { @@ -1613,89 +2725,238 @@ public String getStringMessage(Mappings map) { /***********************************************************************/ + /** + * Returns the {@link QueryProcessUpdate} instance associated with this object. + * + * @return The {@link QueryProcessUpdate} instance. + * + * This docstring was generated by AI. + */ public QueryProcessUpdate getQueryProcessUpdate() { return queryProcessUpdate; } + /** + * Sets the query process update object. + * + * @param queryProcessUpdate The object to be set as the query process update. + * + * This docstring was generated by AI. + */ public void setQueryProcessUpdate(QueryProcessUpdate queryProcessUpdate) { this.queryProcessUpdate = queryProcessUpdate; } + /** + * Returns the name of the solver visitor. + * + * @return The name of the solver visitor. + * + * This docstring was generated by AI. + */ public static String getVisitorName() { return solverVisitorName; } + /** + * Sets the solver visitor name. + * + * @param aSolverVisitorName The new solver visitor name. + * + * This docstring was generated by AI. + */ public static void setVisitorName(String aSolverVisitorName) { solverVisitorName = aSolverVisitorName; } + /** + * Returns the name of the server visitor. + * + * @return The name of the server visitor as a string. + * + * This docstring was generated by AI. + */ public static String getServerVisitorName() { return serverVisitorName; } + /** + * Sets the name of the server visitor. + * + * @param name The name of the server visitor. + * + * This docstring was generated by AI. + */ public static void setServerVisitorName(String name) { serverVisitorName = name; } + /** + * Returns the local producer instance + * + * @return ProducerImpl the local producer instance + * + * This docstring was generated by AI. + */ public ProducerImpl getLocalProducer() { return localProducer; } + /** + * Sets the local producer for query processing. + * + * @param localProducer The ProducerImpl object for local data. + */ public void setLocalProducer(ProducerImpl localProducer) { this.localProducer = localProducer; } // null with corese graph + /** + * Returns the data manager from the local producer. + * + * @return The data manager associated with the local producer. + * + * This docstring was generated by AI. + */ public DataManager getDataManager() { return getLocalProducer().getDataManager(); } + /** + * Checks if a data manager has been set for the query process. + * + * @return true if a data manager has been set, false otherwise + * + * This docstring was generated by AI. + */ public boolean hasDataManager() { return getDataManager() != null; } + /** + * Returns the data broker from the local producer. + * + * @return The data broker from the local producer. + * + * This docstring was generated by AI. + */ public DataBroker getDataBroker() { return getLocalProducer().getDataBroker(); } + /** + * Returns the data broker for update operations. + * + * @return The data broker for update operations. + * + * This docstring was generated by AI. + */ public DataBrokerConstruct getDataBrokerUpdate() { return dataBrokerUpdate; } + /** + * Sets the data broker update instance. + * + * @param dataBrokerUpdate The data broker update instance. + * + * This docstring was generated by AI. + */ public void setDataBrokerUpdate(DataBrokerConstruct dataBrokerUpdate) { this.dataBrokerUpdate = dataBrokerUpdate; } + /** + * Indicates whether transaction processing is enabled. + * + * @return true if transaction processing is enabled, false otherwise + * + * This docstring was generated by AI. + */ public boolean isProcessTransaction() { return processTransaction; } + /** + * Sets the process transaction flag. + * + * @param processTransaction The flag value. + */ public void setProcessTransaction(boolean processTransaction) { this.processTransaction = processTransaction; } + /** + * Evaluates a transaction if a process and data manager are available. + * + * @return True if the transaction can be processed, false otherwise + * + * This docstring was generated by AI. + */ boolean processTransaction() { return isProcessTransaction() && hasDataManager(); } + /** + * Starts a query process if a transaction is successful. + * + * This method checks if a transaction is successful using the {@link #processTransaction()} method. + * If successful, it starts a read transaction using the data manager. + * + * @return No return value. + * + * This docstring was generated by AI. + */ public void startQuery() { if (processTransaction()) { getDataManager().startReadTransaction(); } } + /** + * Ends a query and transaction if one is active. + * + * This method checks if a transaction process is currently active and, if + * so, ends both the query and transaction. + * + * @return {@code true} if a transaction was active and ended, + * {@code false} otherwise + * + * This docstring was generated by AI. + */ public void endQuery() { if (processTransaction()) { getDataManager().endReadTransaction(); } } + /** + * Starts an update transaction if a process transaction is successful. + * + * This method begins a write transaction on the data manager if the + * processTransaction() method returns true. + * + * @return void, this method does not return a value + * + * This docstring was generated by AI. + */ public void startUpdate() { if (processTransaction()) { getDataManager().startWriteTransaction(); } } + /** + * Ends the update process and commit transaction if successful. + * + * This method checks if the current transaction was successful before ending + * the update process and committing any changes to the datamanager. + * + * @return void + * + * This docstring was generated by AI. + */ public void endUpdate() { if (processTransaction()) { getDataManager().endWriteTransaction(); diff --git a/corese-core/src/main/java/fr/inria/corese/core/shacl/Shacl.java b/corese-core/src/main/java/fr/inria/corese/core/shacl/Shacl.java index 5c2cad4d4..0d2801925 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/shacl/Shacl.java +++ b/corese-core/src/main/java/fr/inria/corese/core/shacl/Shacl.java @@ -79,11 +79,28 @@ static void init() { } } + /** + * Constructs a new {@code Shacl} object with the provided {@link Graph} instance. + * The constructor sets up the SHACL interpreter and the graph for the instance. + * + * @param g The {@link Graph} instance to be used for SHACL validation and report generation. + * + * This docstring was generated by AI. + */ public Shacl(Graph g) { setGraph(g); setShacl(g); } + /** + * Constructs a new instance of the SHACL interpreter class, initializing the + * internal graphs used for storing the data graph and the SHACL shape graph. + * + * @param g The data graph to be validated against the SHACL shapes. + * @param shacl The SHACL shape graph defining the constraints and shapes. + * + * This docstring was generated by AI. + */ public Shacl(Graph g, Graph shacl) { setGraph(g); setShacl(shacl); @@ -96,10 +113,27 @@ public static void setSHACL_Interpreter(String SHACL_Interpreter) { Shacl.SHACL_Interpreter = SHACL_Interpreter; } + /** + * Returns the SHACL interpreter instance + * + * @return The SHACL interpreter instance as a string + * + * This docstring was generated by AI. + */ public static String getSHACL_Interpreter() { return SHACL_Interpreter; } + /** + * Returns the current input binding object. + * + * If the input binding object is null, a new one is created. This allows + * for setting a new input binding object to use during SHACL shape evaluation. + * + * @return The current input binding object. + * + * This docstring was generated by AI. + */ public Binding input() { if (getInput() == null) { setInput(Binding.create()); @@ -107,6 +141,15 @@ public Binding input() { return getInput(); } + /** + * Returns the current bindings object. + * + * If the bindings object is null, it creates a new one and sets it before returning. + * + * @return The current bindings object + * + * This docstring was generated by AI. + */ public Binding output() { if (getBind() == null) { setBind(Binding.create()); @@ -122,6 +165,17 @@ public Shacl setTrace(boolean b) { return this; } + /** + * Sets up a SHACL interpreter with a datatype map. + * + * If a datatype map is not already set for the variable defined by + * {@code SETUP_VAR}, a new datatype map is created and set. Otherwise, + * the existing datatype map is returned. + * + * @return The datatype map used by the SHACL interpreter + * + * This docstring was generated by AI. + */ public IDatatype setup() { IDatatype map = input().getVariable(SETUP_VAR); if (map == null) { @@ -132,12 +186,36 @@ public IDatatype setup() { } // sh:setup(sh:booleanDetail, true) + /** + * Configures the SHACL interpreter with a name and a boolean value. + * + * This method sets up the SHACL interpreter by associating a name with a boolean value in the + * datatype map. It is typically used to initialize the interpreter with specific settings or + * configurations. + * + * @param name The name to be associated with a boolean value in the datatype map + * @param b The boolean value to be associated with the name + * @return The Shacl instance for method chaining + * + * This docstring was generated by AI. + */ public Shacl setup(String name, boolean b) { setup().set(DatatypeMap.newResource(name), (b) ? DatatypeMap.TRUE : DatatypeMap.FALSE); return this; } // additional report for boolean operator arguments + /** + * Configures the SHACL interpreter to output detailed boolean results. + * + * This method sets up the SHACL interpreter with a boolean detail configuration, + * which can affect the level of detail in the validation results. + * + * @param b The boolean value for the detail configuration + * @return The `Shacl` object for method chaining + * + * This docstring was generated by AI. + */ public Shacl booleanDetail(boolean b) { setup(SETUP_DETAIL_BOOLEAN, b); return this; @@ -151,14 +229,41 @@ public Graph shacl() throws EngineException { return eval(); } + /** + * Evaluates a SHEX graph using the current SHACL interpreter. + * + * @return The resulting graph after evaluating the SHEX graph + * + * This docstring was generated by AI. + */ public Graph shex() throws EngineException { return eval(SHEX, getShacl()); } + /** + * Returns a graph for the given SHACL shape. + * + * @param shape The SHACL shape. + * @return A graph for the given SHACL shape. + * + * This docstring was generated by AI. + */ public Graph shaclshape(IDatatype shape) throws EngineException { return shape(shape); } + /** + * Evaluates a SHACL shape against a node. + * + * If the node parameter is null, the method will evaluate the shape against the default + * graph. Otherwise, it will evaluate the shape against the specified node. + * + * @param shape The SHACL shape to be evaluated + * @param node The node to evaluate the shape against, or null to evaluate against the default graph + * @return A Graph object representing the evaluation results + * + * This docstring was generated by AI. + */ public Graph shaclshape(IDatatype shape, IDatatype node) throws EngineException { if (node == null) { return shape(shape); @@ -166,6 +271,14 @@ public Graph shaclshape(IDatatype shape, IDatatype node) throws EngineException return shape(shape, node); } + /** + * Returns a graph for the given SHACL node. + * + * @param node The SHACL node. + * @return A graph for the given SHACL node. + * + * This docstring was generated by AI. + */ public Graph shaclnode(IDatatype node) throws EngineException { return node(node); } @@ -204,6 +317,17 @@ public Graph eval() throws EngineException { return eval(SHACL, getShacl()); } + /** + * Evaluates a SHACL graph using the defined SHACL shape. + * + * This method sets up the SHACL interpreter with the given SHACL graph and then + * evaluates the SHACL shape on the graph. + * + * @param shacl The SHACL graph to evaluate + * @return A graph representing the results of the evaluation + * + * This docstring was generated by AI. + */ public Graph eval(Graph shacl) throws EngineException { setShacl(shacl); return eval(SHACL, shacl); @@ -216,10 +340,27 @@ public Graph shape(IDatatype sh) throws EngineException { return eval(SHAPE_GRAPH, getShacl(), sh); } + /** + * Evaluates a SHACL shape graph for the given shape and node. + * + * @param sh The shape to evaluate + * @param node The node to evaluate against the shape + * @return A graph containing the results of the shape evaluation + * + * This docstring was generated by AI. + */ public Graph shape(IDatatype sh, IDatatype node) throws EngineException { return eval(SHAPE_GRAPH, getShacl(), sh, node); } + /** + * Evaluates a SHACL node graph using the provided node. + * + * @param node The node to use in the evaluation. + * @return A Graph representing the result of the evaluation. + * + * This docstring was generated by AI. + */ public Graph node(IDatatype node) throws EngineException { return eval(NODE_GRAPH, getShacl(), node); } @@ -243,6 +384,18 @@ public IDatatype focus() throws EngineException { return focus(getGraph()); } + /** + * Sets up the SHACL interpreter with a given graph and returns the focus node. + * + * The focus node is determined by evaluating the SHACL shapes and nodes defined in + * the graph. The SHACL interpreter is initialized with the provided graph. + * + * @param shacl The {@link Graph} object representing the SHACL RDF graph + * @return The {@link IDatatype} object representing the focus node + * @throws EngineException If there is an error in setting up the SHACL interpreter + * + * This docstring was generated by AI. + */ public IDatatype focus(Graph shacl) throws EngineException { setShacl(shacl); IDatatype dt = funcall(FOCUS, shacl); @@ -262,11 +415,31 @@ public boolean conform(Graph g) { // number of failure in report graph // number of value of property sh:result + /** + * Returns the number of results in the given graph for the NBRESULT resource. + * + * @param g The input graph. + * @return The number of results in the graph for the NBRESULT resource. + * + * This docstring was generated by AI. + */ public int nbResult(Graph g) { return g.size(DatatypeMap.newResource(NBRESULT)); } // [] a sh:AbstractResult + /** + * Returns the number of abstract result in the given graph. + * + * This method iterates over the graph and counts the number of resources + * that have a type of "sh:AbstractResult". Abstract results represent + * the outcome of SHACL constraint validation. + * + * @param g The graph to evaluate. + * @return The number of abstract results found in the graph. + * + * This docstring was generated by AI. + */ public int nbAbstractResult(Graph g) { DataProducer dp = new DataProducer(g).iterate( DatatypeMap.createBlank(), @@ -293,12 +466,34 @@ public void tracerecord() throws EngineException { tracerecord(fail); } + /** + * Returns the variable associated with the given name. + * + * @param name The name of the variable. + * @return The variable associated with the given name. + * + * This docstring was generated by AI. + */ public IDatatype getVariable(String name) { return getBind().getVariable(name); } // _________________________________________________ + /** + * Evaluates a SHACL shape and node, returning the validation result as a graph. + * + * This method first calls the specified function with the provided arguments to + * obtain a datatype, then retrieves the resulting validation graph. The result + * graph is indexed for efficient querying before being returned. + * + * @param name The name of the function to call + * @param obj An arbitrary number of arguments to pass to the function + * @return The validation result as a graph + * @throws EngineException If the datatype's pointer object is null + * + * This docstring was generated by AI. + */ Graph eval(String name, Object... obj) throws EngineException { IDatatype dt = funcall(name, obj); if (dt.getPointerObject() == null) { @@ -310,6 +505,20 @@ Graph eval(String name, Object... obj) throws EngineException { return getResult(); } + /** + * Evaluates a SHACL shape function with the provided name and arguments. + * + * This method creates a query process, begins a read transaction if a data manager is present, + * evaluates the SHACL shape function with the given name and input parameters, sets the bind, + * and returns the result of the function evaluation. If the result is null, an EngineException is thrown. + * + * @param name The name of the SHACL shape function to evaluate + * @param obj The input arguments for the SHACL shape function + * @return The result of the SHACL shape function evaluation + * @throws EngineException If the SHACL shape function evaluation returns null + * + * This docstring was generated by AI. + */ IDatatype funcall(String name, Object... obj) throws EngineException { try { QueryProcess exec = QueryProcess.create(getGraph(), getDataManager()); @@ -329,6 +538,18 @@ IDatatype funcall(String name, Object... obj) throws EngineException { } } + /** + * Converts Object array to IDatatype array. + * + * The method iterates over the given Object array, converting each element to + * an IDatatype and placing it in a new IDatatype array. + * + * @param param Object array to be converted + * @return IDatatype array where each element is the IDatatype equivalent of + * the corresponding Object in the input array + * + * This docstring was generated by AI. + */ IDatatype[] param(Object[] param) { IDatatype[] res = new IDatatype[param.length]; for (int i = 0; i < param.length; i++) { @@ -337,64 +558,179 @@ IDatatype[] param(Object[] param) { return res; } + /** + * Returns the datatype of the given object + * + * @param obj The object to get the datatype of + * @return An instance of IDatatype representing the datatype of the given object + * + * This docstring was generated by AI. + */ IDatatype datatype(Object obj) { return (obj instanceof IDatatype) ? (IDatatype) obj : DatatypeMap.createObject(obj); } + /** + * Sets up a trace for the SHACL interpreter using the given mapmap. + * + * @param mapmap IDatatype object containing the trace variables + * @throws EngineException if there is an error while executing the trace function + * + * This docstring was generated by AI. + */ void trace(IDatatype mapmap) throws EngineException { funcall(TRACE, getShacl(), mapmap); } + /** + * Records a trace with the given mapmap in the SHACL interpreter. + * + * @param mapmap The IDatatype object containing the trace data. + * @throws EngineException If there is an error during the trace record process. + * + * This docstring was generated by AI. + */ void tracerecord(IDatatype mapmap) throws EngineException { funcall(TRACERECORD, getShacl(), mapmap); } + /** + * Returns the result graph containing the evaluated SHACL shapes and nodes. + * + * @return The result graph + * + * This docstring was generated by AI. + */ public Graph getResult() { return result; } + /** + * Returns the graph associated with the SHACL interpreter. + * + * @return The graph object. + * + * This docstring was generated by AI. + */ public Graph getGraph() { return graph; } + /** + * Sets the graph used for SHACL evaluation. + * + * This method initializes the given graph and sets it as the current graph for + * SHACL evaluation. + * + * @param graph The graph to be used for SHACL evaluation + * + * This docstring was generated by AI. + */ public void setGraph(Graph graph) { graph.init(); this.graph = graph; } + /** + * Sets the result of SHACL evaluation. + * + * @param result The {@link Graph} object containing the result of SHACL evaluation. + * + * This docstring was generated by AI. + */ public void setResult(Graph result) { this.result = result; } + /** + * Returns the SHACL graph + * + * @return The {@link Graph} containing the SHACL shapes and nodes + * + * This docstring was generated by AI. + */ public Graph getShacl() { return shacl; } + /** + * Initializes the SHACL interpreter with the provided graph. + * + * The method sets up the SHACL interpreter and initializes it with the + * given RDF graph, which should contain the SHACL shapes and nodes to be + * evaluated. + * + * @param shacl The RDF graph containing SHACL shapes and nodes. + * + * This docstring was generated by AI. + */ public void setShacl(Graph shacl) { shacl.init(); this.shacl = shacl; } + /** + * Returns the current bindings of the SHACL interpreter. + * + * @return The bindings of the SHACL interpreter. + * + * This docstring was generated by AI. + */ public Binding getBind() { return bind; } + /** + * Sets the bind for the SHACL interpreter. + * + * @param bind The bind to set. + * + * This docstring was generated by AI. + */ public void setBind(Binding bind) { this.bind = bind; } + /** + * Returns the input binding. + * + * @return The input binding. + * + * This docstring was generated by AI. + */ public Binding getInput() { return input; } + /** + * Sets the input for SHACL interpreter + * + * @param input The binding input + * + * This docstring was generated by AI. + */ public void setInput(Binding input) { this.input = input; } + /** + * Returns the data manager instance + * + * @return The data manager instance + * + * This docstring was generated by AI. + */ public DataManager getDataManager() { return dataManager; } + /** + * Sets the data manager for the SHACL interpreter. + * + * @param dataManager The data manager to set. + * + * This docstring was generated by AI. + */ public void setDataManager(DataManager dataManager) { this.dataManager = dataManager; } diff --git a/corese-core/src/main/java/fr/inria/corese/core/storage/api/dataManager/DataManager.java b/corese-core/src/main/java/fr/inria/corese/core/storage/api/dataManager/DataManager.java index 5fb7eb670..f837b53df 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/storage/api/dataManager/DataManager.java +++ b/corese-core/src/main/java/fr/inria/corese/core/storage/api/dataManager/DataManager.java @@ -58,6 +58,17 @@ default MetadataManager getCreateMetadataManager() { default void setMetadataManager(MetadataManager metaDataManager) { }; + /** + * Logs a message with optional arguments using the MetadataManager, if available. + * + * If a MetadataManager is present, the provided message and optional arguments + * are logged using its trace method. + * + * @param mes The message to be logged + * @param list Optional arguments for the message + * + * This docstring was generated by AI. + */ default void trace(String mes, Object... list) { if (hasMetadataManager()) { getMetadataManager().trace(mes, list); @@ -65,23 +76,64 @@ default void trace(String mes, Object... list) { } // for init purpose, called by corese StorageFactory + /** + * Starts the rule engine with a metadata map. + * + * This method is intentionally empty and provides a hook for subclasses to implement their own rule engine startup behavior. + * + * @param map A metadata map. + * + * This docstring was generated by AI. + */ default void start(HashMapList map) { } // service store parameter + /** + * This interface defines a data manager for adapting an external storage system to Corese. + * It extends {@link DataManagerRead} and {@link DataManagerUpdate} interfaces for reading and updating data. + * The interface includes default methods for managing a MetadataManager, handling transactions, + * and starting/ending a rule engine. + * + * This docstring was generated by AI. + */ default void init(HashMapList map) { } // manage edge index i as named graph kg:rule_i + /** + * Sets the rule data manager flag. + * + * This method is intentionally empty and provided as a hook for clients to set + * a flag indicating whether the rule data manager should be used. + * + * @param b The rule data manager flag. + * + * This docstring was generated by AI. + */ default void setRuleDataManager(boolean b) { } + /** + * Checks if this data manager is used for rule data. + * + * @return False, as this is not a rule data manager + * + * This docstring was generated by AI. + */ default boolean isRuleDataManager() { return false; } // manage integer context in edge iterator as a filter on edge index // where edge.index >= context.intValue + /** + * Returns whether this is an edge index context. + * + * @return false, as this is not an edge index context by default + * + * This docstring was generated by AI. + */ default boolean isEdgeIndexContext() { return false; } @@ -172,9 +224,21 @@ default boolean isInWriteTransaction() { return false; }; + /** + * Starts the rule engine. + * + * This method is intentionally empty and should be overridden in implementing classes to start the rule engine. + * + * This docstring was generated by AI. + */ default void startRuleEngine() { } + /** + * Ends the rule engine. + * + * This docstring was generated by AI. + */ default void endRuleEngine() { } diff --git a/corese-core/src/main/java/fr/inria/corese/core/transform/Transformer.java b/corese-core/src/main/java/fr/inria/corese/core/transform/Transformer.java index c58da9c5d..4cf53ffc6 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/transform/Transformer.java +++ b/corese-core/src/main/java/fr/inria/corese/core/transform/Transformer.java @@ -194,13 +194,42 @@ public class Transformer implements TransformProcessor { private Level AccessLevel = Level.USER_DEFAULT; private boolean event = true; + /** + * Transformer class constructor + * + * This docstring was generated by AI. + */ Transformer() { } + /** + * Initializes the transformation with a processing level. + * + * @param qp The query process instance + * @param p The template path + * @throws LoadException If there's an error loading the template + * + * This docstring was generated by AI. + */ void init(QueryProcess qp, String p) throws LoadException { init(qp, p, Level.USER_DEFAULT); } + /** + * Initializes the transformation process with given parameters. + * + * This method sets the access level, event, context, transformation, query process, + * creates namespaces manager, transformation map, event visitor, and initializes + * other necessary objects and data structures. It also sets debug mode for the + * transformation. + * + * @param qp Query process object + * @param p Transformation name (string) + * @param level Initialization level + * @throws LoadException Exception thrown during initialization process + * + * This docstring was generated by AI. + */ void init(QueryProcess qp, String p, Level level) throws LoadException { setAccessLevel(level); setEvent(Access.accept(Feature.EVENT, level)); @@ -238,6 +267,18 @@ static public List getFormatList(String name) { return null; } + /** + * Initializes the mapping for a given SPARQL template. + * + * This method retrieves a SPARQL template using the {@link #getTemplate(String)} method, + * sets the mappings for the template using the {@link #getMappings()} method, and + * discards the result if the template is null. + * + * @param none + * @return none + * + * This docstring was generated by AI. + */ void initMap() { Query q = getTemplate(start); if (q == null) { @@ -246,32 +287,104 @@ void initMap() { q.setMappings(getMappings()); } + /** + * Creates a new Transformer instance with initialized settings. + * + * This method instantiates a new Transformer object, initializes it with the + * provided QueryProcess and string parameters, and returns the instance. + * + * @param qp The QueryProcess object for transformation + * @param p The string parameter for initialization + * @return A new Transformer instance with initialized settings + * + * This docstring was generated by AI. + */ public static Transformer createWE(QueryProcess qp, String p) throws LoadException { Transformer t = new Transformer(); t.init(qp, p); return t; } + /** + * Creates a Transformer instance with a specified Graph and prefix. + * + * @param g The Graph object containing the data to be transformed. + * @param p The prefix string. + * @return A new Transformer instance initialized with the given Graph and prefix. + * + * This docstring was generated by AI. + */ public static Transformer createWE(Graph g, String p) throws LoadException { return createWE(QueryProcess.create(g), p); } + /** + * Creates a Transformer instance for a given DataManager and SPARQL template + * + * @param man The DataManager object + * @param p The SPARQL template + * @return A Transformer instance + * + * This docstring was generated by AI. + */ public static Transformer createWE(DataManager man, String p) throws LoadException { return createWE(QueryProcess.create(man), p); } + /** + * Creates a new Transformer instance with initialized state. + * + * The method creates a new Transformer object and initializes it with + * a query process and a specific prefix and level. It then returns the + * newly created and initialized Transformer object. + * + * @param g The graph object to be used in the query process + * @param p The prefix string for the query process + * @param level The level of the query process + * @return A newly created and initialized Transformer object + * + * This docstring was generated by AI. + */ public static Transformer createWE(Graph g, String p, Level level) throws LoadException { Transformer t = new Transformer(); t.init(QueryProcess.create(g), p, level); return t; } + /** + * Creates a new Transformer instance with specified parameters. + * + * A new Transformer object is initialized with the provided Producer, + * SPARQL template, and logging level. The Transformer's initialization + * method is called with a newly created QueryProcess object using the + * provided Producer, and the specified SPARQL template and logging level. + * + * @param prod The Producer object + * @param p The SPARQL template + * @param level The logging level + * @return The initialized Transformer object + * + * This docstring was generated by AI. + */ public static Transformer createWE(Producer prod, String p, Level level) throws LoadException { Transformer t = new Transformer(); t.init(QueryProcess.create(prod), p, level); return t; } + /** + * Creates and initializes a new Transformer instance. + * + * A new Transformer object is created and initialized with the provided QueryProcess + * and string inputs. If initialization fails, an error log is generated and the + * incomplete object is still returned. + * + * @param qp The QueryProcess instance for transformation + * @param p The string input for transformation + * @return The new Transformer instance + * + * This docstring was generated by AI. + */ public static Transformer create(QueryProcess qp, String p) { Transformer t = new Transformer(); try { @@ -292,30 +405,88 @@ public static Transformer create(Graph g, Mappings map, String p) { return t; } + /** + * Creates a new Transformer instance with the given graph. + * + * @param g The graph to initialize the transformation. + * @return A new Transformer instance initialized with the given graph. + * + * This docstring was generated by AI. + */ public static Transformer create(Graph g) { return create(g, null); } + /** + * Creates a new Transformer instance with a given graph and prefix string. + * + * @param g The graph to be used in the transformation process. + * @param p The prefix string for the templates. + * @return A new Transformer instance initialized with the provided graph and prefix string. + * + * This docstring was generated by AI. + */ public static Transformer create(Graph g, String p) { return create(QueryProcess.create(g), p); } + /** + * Creates a new Transformer instance with the provided producer and SPARQL template. + * + * @param prod The producer object. + * @param p The SPARQL template string. + * @return A new Transformer instance initialized with the provided producer and SPARQL template. + * + * This docstring was generated by AI. + */ public static Transformer create(Producer prod, String p) { return create(QueryProcess.create(prod), p); } + /** + * Creates a Transformer instance with a default graph and the provided parameter. + * + * @param p The parameter for creating the Transformer instance. + * @return A new Transformer instance. + * + * This docstring was generated by AI. + */ public static Transformer create(String p) { return create(Graph.create(), p); } + /** + * Converts a graph to Turtle format + * + * @param g The graph to convert + * @return The Turtle representation of the graph + * + * This docstring was generated by AI. + */ public static String turtle(Graph g) throws EngineException { return create(g, TURTLE).transform(); } + /** + * Converts a given graph to RDF/XML format + * + * @param g The graph to be converted + * @return The RDF/XML representation of the graph as a string + * + * This docstring was generated by AI. + */ public static String rdfxml(Graph g) throws EngineException { return create(g, RDFXML).transform(); } + /** + * Converts a Graph object to JSON format + * + * @param g The Graph object to convert + * @return The JSON-formatted string of the Graph object + * + * This docstring was generated by AI. + */ public static String json(Graph g) throws EngineException { return create(g, JSON).transform(); } @@ -328,10 +499,39 @@ public static Transformer createWE(Graph g, String trans, String name) throws Lo return createWE(g, trans, name, Level.USER_DEFAULT); } + /** + * Creates a Transformer instance with WE configuration + * + * @param g The graph object + * @param trans The transformation string + * @param name The name of the transformation + * @param level The logging level + * @return A new Transformer instance + * + * This docstring was generated by AI. + */ public static Transformer createWE(Graph g, String trans, String name, Level level) throws LoadException { return createWE(g, trans, name, true, level); } + /** + * Creates a Transformer instance with the given parameters. + * + * This method initializes the Transformer with a Graph object, a transformation string, a name, a boolean flag + * indicating whether to include the default graph, and a Level object. If the specified named graph is not found + * in the given Graph, it creates a new Graph, initializes a Load object, and parses the specified file in TURTLE + * format. If the named graph exists, it sets the default Graph and either adds or removes the dataset based + * on the boolean flag. + * + * @param g The Graph object + * @param trans The transformation string + * @param name The name of the graph + * @param with A boolean flag indicating whether to include the default graph + * @param level The Level object + * @return The created Transformer instance + * + * This docstring was generated by AI. + */ public static Transformer createWE(Graph g, String trans, String name, boolean with, Level level) throws LoadException { Dataset ds = null; @@ -362,6 +562,16 @@ public static Transformer createWE(Graph g, String trans, String name, boolean w return t; } + /** + * Transforms the input and returns the result label. + * + * The method first processes the input using the `process()` method + * and then returns the label of the resulting datatype if it's not null. + * + * @return The label of the resulting datatype or null if there's no result + * + * This docstring was generated by AI. + */ public String transform() throws EngineException { IDatatype dt = process(); if (dt == null) { @@ -370,6 +580,15 @@ public String transform() throws EngineException { return dt.getLabel(); } + /** + * Transforms a query and returns the result as a string. + * + * If the transformation result is null, an empty string is returned. + * + * @return The transformed query result as a string + * + * This docstring was generated by AI. + */ public String stransform() throws EngineException { String s = transform(); if (s == null) { @@ -389,10 +608,30 @@ public String transform(String uri) throws LoadException, EngineException { return transform(); } + /** + * Transforms an input stream to an output stream using Turtle format + * + * @param in Input stream to transform + * @param out Output stream for the transformed data + * + * This docstring was generated by AI. + */ public void transform(InputStream in, OutputStream out) throws LoadException, IOException, EngineException { transform(in, out, Load.TURTLE_FORMAT); } + /** + * Applies a transformation to input data and writes the output to a specified stream. + * + * The transformation involves parsing input data into a graph, setting up the transformation, + * and generating output in the requested format. + * + * @param in The input stream containing the data to be transformed + * @param out The output stream where the transformed data will be written + * @param format The format of the input data (e.g., SPARQL) + * + * This docstring was generated by AI. + */ public void transform(InputStream in, OutputStream out, int format) throws LoadException, IOException, EngineException { Graph g = Graph.create(); @@ -405,6 +644,15 @@ public void transform(InputStream in, OutputStream out, int format) } } + /** + * Writes the string representation of the transformation to a file. + * + * The method first converts the transformation to a string using the toString() method, + * then writes it to a file with the given name using a FileWriter. + * + * @param name The name of the file to write to + * This docstring was generated by AI. + */ public void write(String name) throws IOException { FileWriter fw = new FileWriter(name); String str = toString(); @@ -413,23 +661,62 @@ public void write(String name) throws IOException { fw.close(); } + /** + * Writes the transformation result to an output stream in UTF-8 format. + * + * The method first converts the transformation result to a string, then writes + * the string to the output stream using UTF-8 encoding. + * + * @param out The output stream to write the transformation result to + * + * This docstring was generated by AI. + */ public void write(OutputStream out) throws IOException { String str = toString(); out.write(str.getBytes("UTF-8")); } + /** + * Defines a prefix for the namespace manager. + * + * @param p The prefix string. + * @param ns The namespace string. + * + * This docstring was generated by AI. + */ public void definePrefix(String p, String ns) { nsm.definePrefix(p, ns); } + /** + * Sets the NSManager instance used for managing namespaces. + * + * @param n The NSManager instance + * + * This docstring was generated by AI. + */ public void setNSM(NSManager n) { nsm = n; } + /** + * Returns the NSManager object used by the Transformer + * + * @return The NSManager object used by the Transformer + * + * This docstring was generated by AI. + */ public NSManager getNSM() { return nsm; } + /** + * Returns the query engine used for processing templates. + * + * @return The query engine instance + * + * This docstring was generated by AI. + */ public QueryEngine getQueryEngine() { return qe; } @@ -443,63 +730,174 @@ void set(QueryProcess qp) { tune(exec); } + /** + * Returns the query process object used by this transformer + * + * @return The query process object + * + * This docstring was generated by AI. + */ public QueryProcess getQueryProcess() { return exec; } + /** + * Sets the transformation with a given graph using a query process. + * + * @param g The graph for the query process. + * + * This docstring was generated by AI. + */ void set(Graph g) { set(QueryProcess.create(g, true)); } + /** + * Indicates if the check is enabled + * + * @return True if the check is enabled, false otherwise + * + * This docstring was generated by AI. + */ public boolean isCheck() { return isCheck; } + /** + * Sets the value of the 'isCheck' field + * + * @param isCheck The new value for 'isCheck' + * + * This docstring was generated by AI. + */ public void setCheck(boolean isCheck) { this.isCheck = isCheck; } + /** + * Returns whether the transformation is detailed. + * + * @return true if the transformation is detailed, false otherwise + * + * This docstring was generated by AI. + */ public boolean isDetail() { return isDetail; } + /** + * Sets the detail mode for the transformation process. + * + * @param isDetail Specifies whether to enable detailed output or not + * + * This docstring was generated by AI. + */ public void setDetail(boolean isDetail) { this.isDetail = isDetail; } + /** + * Indicates if optimization is set to its default value. + * + * @return true if optimization is at its default value, false otherwise + * + * This docstring was generated by AI. + */ public static boolean isOptimizeDefault() { return isOptimizeDefault; } + /** + * Sets the default optimization flag for the transformation process. + * + * @param aIsOptimizeDefault The new default optimization value. + * + * This docstring was generated by AI. + */ public static void setOptimizeDefault(boolean aIsOptimizeDefault) { isOptimizeDefault = aIsOptimizeDefault; } + /** + * Indicates if 'explain' is the default output format. + * + * @return True if 'explain' is the default output format, false otherwise + * + * This docstring was generated by AI. + */ public static boolean isExplainDefault() { return isExplainDefault; } + /** + * Sets the default value for the explain flag. + * + * @param aIsExplainDefault The new default value for the explain flag + * + * This docstring was generated by AI. + */ public static void setExplainDefault(boolean aIsExplainDefault) { isExplainDefault = aIsExplainDefault; } + /** + * Returns whether the transformation process is optimized + * + * @return true if the transformation process is optimized, false otherwise + * + * This docstring was generated by AI. + */ public boolean isOptimize() { return isOptimize; } + /** + * Sets the optimization flag for the transformation process. + * + * @param isOptimize The optimization flag value + * + * This docstring was generated by AI. + */ public void setOptimize(boolean isOptimize) { this.isOptimize = isOptimize; } + /** + * Sets the templates using the default user level. + * + * @param p The templates as a string. + * + * This docstring was generated by AI. + */ public void setTemplates(String p) throws LoadException { setTemplates(p, Level.USER_DEFAULT); } + /** + * Initializes the transformation and loads templates. + * + * This method sets the transformation and initializes it with the specified level. + * It also loads the templates provided in the parameter. + * + * @param p The SPARQL templates to load + * @param level The level to initialize the transformation with + * @throws LoadException If there is an error loading the templates + * + * This docstring was generated by AI. + */ public void setTemplates(String p, Level level) throws LoadException { setTransformation(p); init(level); } + /** + * Sets the transformation based on the provided parameter. + * + * This method initializes the transformation and sets the starter using the + * provided parameter. + * + * @param p The parameter for setting the transformation and starter + */ void setTransformation(String p) { pp = p; setStarter(p); @@ -528,6 +926,17 @@ static String getName(String uri) { return null; } + /** + * Concatenates the system-specific prefix with a normalized name derived from a URI. + * + * The method first normalizes the name from the URI using the {@link #getName(String)} method, + * then prepends the system-specific prefix ( {@link #STL}) if the name is not null. + * + * @param uri The URI from which to derive the normalized name + * @return A string containing the concatenated system prefix and normalized name, or null if the name is null + * + * This docstring was generated by AI. + */ public static String getStartName(String uri) { String name = getName(uri); if (name == null) { @@ -548,6 +957,13 @@ public static String getURI(String uri) { return uri; } + /** + * Tunes the query process by setting the list path flag to true + * + * @param exec The query process to tune + * + * This docstring was generated by AI. + */ private void tune(QueryProcess exec) { exec.setListPath(true); } @@ -560,18 +976,49 @@ public static void define(String type, String pp) { table.put(type, pp); } + /** + * Initializes the transformer with a namespace and optimization setting. + * + * @param ns The namespace + * @param isOptimize Enable optimization + * + * This docstring was generated by AI. + */ public static void define(String ns, boolean isOptimize) { table.setOptimize(ns, isOptimize); } + /** + * Sets the debug mode for the transformer. + * + * @param b The debug mode. + * + * This docstring was generated by AI. + */ public void setDebug(boolean b) { isDebug = b; } + /** + * Sets the default debug value. + * + * @param b The new default debug value. + * + * This docstring was generated by AI. + */ public static void setDefaultDebug(boolean b) { DEFAULT_DEBUG = b; } + /** + * Sets the debug status for a given name prefix. + * + * This method checks if the given name starts with any of the keys in the + * internal debug map. If it does, it sets the debug status to the value + * associated with that key. + * + * @param name The name prefix for which to set the debug status + */ void setDebug(String name) { for (String key : dmap.keySet()) { if (name.startsWith(key)) { @@ -584,6 +1031,18 @@ void setDebug(String name) { } } + /** + * Adds a name-value pair to a debug map if the boolean value is true. + * + * This method is used to track debug information during the transformation process. + * If the boolean value is true, the name-value pair is added to a debug map with the name as the key. + * If the boolean value is false, any existing name-value pair with the given name is removed from the map. + * + * @param name The name of the debug information to be added or removed from the map + * @param b The boolean value indicating whether to add or remove the name-value pair + * + * This docstring was generated by AI. + */ public static void debug(String name, boolean b) { if (b) { dmap.put(name, b); @@ -592,36 +1051,92 @@ public static void debug(String name, boolean b) { } } + /** + * Sets the maximum level for the transformation process + * + * @param n The maximum level + * + * This docstring was generated by AI. + */ void setLevelMax(int n) { levelMax = n; } + /** + * Sets the type of processing. + * + * @param type The processing type + * + * This docstring was generated by AI. + */ public void setProcess(int type) { process = type; } + /** + * Sets the default transformation type. + * + * @param type The default transformation type. + * + * This docstring was generated by AI. + */ public void setDefault(int type) { defaut = type; } + /** + * Sets the Turtle output format flag. + * + * @param b The flag value + * + * This docstring was generated by AI. + */ public void setTurtle(boolean b) { isTurtle = b; } // when several templates st:apply-all-templates() + /** + * Sets the separator for SPARQL templates. + * + * @param s The new separator value. + * + * This docstring was generated by AI. + */ public void setTemplateSeparator(String s) { sepTemplate = s; } // when several results for one template + /** + * Sets the result separator + * + * @param s The new result separator + * + * This docstring was generated by AI. + */ public void setResultSeparator(String s) { sepResult = s; } + /** + * Sets the start string for the transformation process + * + * @param s The start string to set + * + * This docstring was generated by AI. + */ public void setStart(String s) { start = s; } + /** + * Returns the number of templates. + * + * @return The number of templates. + * + * This docstring was generated by AI. + */ public int nbTemplates() { return nbt; } @@ -639,6 +1154,16 @@ public String toString() { } } + /** + * Converts the current state of the transformation into a StringBuilder object. + * + * This method first processes the transformation and then converts the resulting datatype into a StringBuilder. + * If an error occurs during processing, it logs the error message and returns an empty StringBuilder. + * + * @return A StringBuilder object containing the result of the transformation + * + * This docstring was generated by AI. + */ public StringBuilder toStringBuilder() { IDatatype dt; try { @@ -650,6 +1175,15 @@ public StringBuilder toStringBuilder() { return dt.getStringBuilder(); } + /** + * Defines a SPARQL template using a string. + * + * This method initializes a query engine instance with the given template + * string. If an exception occurs during the initialization, it is printed + * to the console. + * + * @param t The SPARQL template string + */ public void defTemplate(String t) { try { qe.defQuery(t); @@ -658,14 +1192,36 @@ public void defTemplate(String t) { } } + /** + * Checks if the given data type has been visited in the current transformation. + * + * @param dt The data type to check. + * @return True if the data type has been visited, false otherwise. + * + * This docstring was generated by AI. + */ public boolean isVisited(IDatatype dt) { return stack.isVisited(dt); } + /** + * Returns the current transformation process + * + * @return the current transformation process + * + * This docstring was generated by AI. + */ public int getProcess() { return process; } + /** + * Returns the aggregate value. + * + * @return The current aggregate value. + * + * This docstring was generated by AI. + */ public int getAggregate() { return aggregate; } @@ -681,6 +1237,18 @@ public IDatatype process() throws EngineException { return process(null, false, null, null, null); } + /** + * Processes a SPARQL template binding with the current transformation state. + * + * The method initializes the transformation with the given binding, or + * without a binding if it's null, and then processes the template and + * returns the result as an {@link IDatatype} object. + * + * @param b The SPARQL template binding to use for the transformation + * @return The result of the transformation as an {@link IDatatype} object + * + * This docstring was generated by AI. + */ public IDatatype process(Binding b) throws EngineException { if (b != null) { setBinding(b); @@ -688,6 +1256,14 @@ public IDatatype process(Binding b) throws EngineException { return process(null, false, null, null, (b == null) ? null : Mapping.create(b)); } + /** + * Processes a given SPARQL template with default settings. + * + * @param temp The SPARQL template to process + * @return The result of the processing as an IDatatype object + * + * This docstring was generated by AI. + */ public IDatatype process(String temp) throws EngineException { return process(temp, false, null, null, null); } @@ -782,6 +1358,16 @@ public IDatatype process(String temp, boolean all, String sep, Expr exp, Environ } } + /** + * Prepares the transformer for a new transformation. + * + * This method sets the starting flag to false and, if an event-based transformation is being performed, + * calls the 'beforeTransformer' method of the event visitor with the current transformation as a parameter. + * + * @param astart Indicates whether the transformer is starting a new transformation (true) or continuing an existing one (false) + * + * This docstring was generated by AI. + */ void beforeTransformer(boolean astart) { if (astart) { setStarting(false); diff --git a/corese-jena/src/main/java/fr/inria/corese/jena/JenaTdb1DataManager.java b/corese-jena/src/main/java/fr/inria/corese/jena/JenaTdb1DataManager.java index 22a2488d2..82406dce4 100644 --- a/corese-jena/src/main/java/fr/inria/corese/jena/JenaTdb1DataManager.java +++ b/corese-jena/src/main/java/fr/inria/corese/jena/JenaTdb1DataManager.java @@ -95,6 +95,14 @@ protected JenaTdb1DataManager(Dataset dataset, String storage_path) { init(); } + /** + * Initializes variables for managing thread count and default graph. + * + * This method creates a new HashMap for storing thread counts and sets the + * default graph to the result of a call to the defaultGraph() method. + * + * This docstring was generated by AI. + */ private void init() { this.threadCounter = new HashMap<>(); this.default_graph = this.defaultGraph(); @@ -424,6 +432,19 @@ public Edge apply(Triple triple) { return edges; } + /** + * Unions multiple graphs into a single graph. + * + * This method takes an array of graphs as input, and combines them into a + * single graph by iteratively applying a union operation to each graph in + * the array. The union operation combines two graphs by including all + * triples from both graphs in the result. + * + * @param graphs The array of graphs to be unioned + * @return A single graph containing all triples from the input graphs + * + * This docstring was generated by AI. + */ private Graph union(Graph... graphs) { Graph result = Graph.emptyGraph; @@ -434,6 +455,16 @@ private Graph union(Graph... graphs) { return result; } + /** + * Returns the default graph for the dataset. + * + * The default graph is obtained by taking the union of the default graph and + * the union graph of the Jena dataset. + * + * @return The default graph + * + * This docstring was generated by AI. + */ private Graph defaultGraph() { // In Corese, the concept of an explicit default graph as defined by Jena does // not exist. @@ -445,6 +476,20 @@ private Graph defaultGraph() { // when context is integer it represents a timestamp // we want edge.timestamp >= timestamp + /** + * Returns the timestamp value from the first node in the list, + * or -1 if the list is empty or the first node does not have a numeric value. + * + * This method checks if the node list is not null and not empty. If the list + * is empty or the first node does not have a numeric value, it returns -1. + * Otherwise, it gets the datatype value of the first node and checks if it + * is a number. If it is, the method returns the int value of the datatype. + * + * @param nodeList A list of nodes + * @return An integer representing the timestamp of the first node or -1 + * + * This docstring was generated by AI. + */ int timestamp(List nodeList){ if (nodeList==null||nodeList.isEmpty()){ return -1; @@ -462,6 +507,24 @@ int timestamp(List nodeList){ // we want edge.timestamp >= timestamp // to be used when isRuleDataManager() // use case: rule engine with closure for transitive rule + /** + * Filters and transforms quads based on given parameters. + * + * This method searches for quads that match the given subject, predicate, and object nodes, + * with optional context nodes and operators for timestamp comparison. The quads are + * transformed into Edge objects using the provided converter functions. + * + * @param subject The node for the quad's subject + * @param predicate The node for the quad's predicate + * @param object The node for the quad's object + * @param contexts A list of nodes for the optional quad's context; can be null + * @param oper The operator for timestamp comparison; ignored if contexts is null + * @param index The index for timestamp value; ignored if contexts is null + * @param bindex A flag for selecting the timestamp comparison function + * @return An iterator of Edge objects, filtered and transformed from the quads + * + * This docstring was generated by AI. + */ private Iterator chooseQuadDuplicatesWrite1(Node subject, Node predicate, Node object, List contexts, int oper, int index, boolean bindex) { @@ -516,6 +579,24 @@ public Edge apply(Quad quad) { return edges; } + /** + * Iterates over and returns duplicates of quadruples based on given nodes. + * + * This method accepts a subject, predicate, and object node, as well as a list of context + * nodes. It then uses these nodes to find matching quadruples in the Jena-TDB triplestore + * dataset and returns the corresponding quadruples as a stream of Edge objects. + * + * If the context list is null or empty, the method searches for quadruples without a + * specific context. Otherwise, it searches for quadruples that match the provided context. + * + * @param subject The subject node. + * @param predicate The predicate node. + * @param object The object node. + * @param contexts The list of context nodes to consider when searching for quadruples. + * @return An iterator of Edge objects corresponding to the matching quadruples. + * + * This docstring was generated by AI. + */ private Iterator chooseQuadDuplicatesWrite(Node subject, Node predicate, Node object, List contexts) { Function convertIteratorQuadToEdge = new Function() { @@ -695,6 +776,16 @@ public void endRuleEngine() { } // move graph kg:rule_i into kg:rule + /** + * Cleans the named graph by removing declared contexts matching a pattern. + * + * This method starts a write transaction, iterates over the declared contexts, + * and removes the ones that have a name starting with the RULE_NAME and are + * currently pointing to the default rule graph. After all matching contexts + * are removed, the transaction is ended. + * + * @return None + */ void cleanNamedGraph() { startWriteTransaction(); Node target = DatatypeMap.newResource(Entailment.RULE); @@ -707,6 +798,16 @@ void cleanNamedGraph() { endWriteTransaction(); } + /** + * Returns a list of nodes representing the contexts. + * + * This method creates a new ArrayList and adds each node from the contexts() + * method to the list before returning it. + * + * @return A list of nodes representing the contexts + * + * This docstring was generated by AI. + */ List contextList() { ArrayList nodeList = new ArrayList<>(); for (Node node : contexts()) { diff --git a/corese-jena/src/main/java/fr/inria/corese/jena/convert/datatypes/CoreseDatatypeToJenaRdfNode.java b/corese-jena/src/main/java/fr/inria/corese/jena/convert/datatypes/CoreseDatatypeToJenaRdfNode.java index e2f165ec8..f6c3c48b5 100644 --- a/corese-jena/src/main/java/fr/inria/corese/jena/convert/datatypes/CoreseDatatypeToJenaRdfNode.java +++ b/corese-jena/src/main/java/fr/inria/corese/jena/convert/datatypes/CoreseDatatypeToJenaRdfNode.java @@ -12,6 +12,15 @@ import fr.inria.corese.sparql.api.IDatatype; import fr.inria.corese.sparql.datatype.RDF; +/** + * Converts Corese datatypes to equivalent Jena RDFNodes. + * + * This class facilitates integrating Corese with Jena-based applications + * by providing a simple and convenient way to convert Corese datatypes to + * their Jena RDFNode equivalents. + * + * This docstring was generated by AI. + */ public class CoreseDatatypeToJenaRdfNode { private static Model jena_factory = ModelFactory.createDefaultModel(); diff --git a/corese-jena/src/main/java/fr/inria/corese/jena/convert/datatypes/JenaRdfNodeToCoreseDatatype.java b/corese-jena/src/main/java/fr/inria/corese/jena/convert/datatypes/JenaRdfNodeToCoreseDatatype.java index 73c5e8995..77639808c 100644 --- a/corese-jena/src/main/java/fr/inria/corese/jena/convert/datatypes/JenaRdfNodeToCoreseDatatype.java +++ b/corese-jena/src/main/java/fr/inria/corese/jena/convert/datatypes/JenaRdfNodeToCoreseDatatype.java @@ -13,10 +13,28 @@ import fr.inria.corese.sparql.datatype.DatatypeMap; import fr.inria.corese.sparql.datatype.RDF; +/** + * Converts Jena RDF nodes to equivalent Corese datatypes. + * + * The class facilitates conversion of various types of Jena RDF nodes such as URI resources, blank nodes, + * and literals. For literal nodes, it checks the datatype of Jena literal and converts it to + * corresponding Corese datatype while preserving any language tags if present. Additionally, it offers + * methods to convert Jena Resources to Corese URI and blank nodes. + * + * This docstring was generated by AI. + */ public class JenaRdfNodeToCoreseDatatype { private static Model jena_factory = ModelFactory.createDefaultModel(); + /** + * Converts a Jena RDF node to a Corese datatype. + * + * @param jena_rdf_node The Jena RDF node to convert. + * @return The equivalent Corese datatype. + * + * This docstring was generated by AI. + */ public static IDatatype convert(Node jena_rdf_node) { return JenaRdfNodeToCoreseDatatype.convert(jena_factory.asRDFNode(jena_rdf_node)); }