Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
34571e5
Corriger les bugs signalés comme bloquants
abdessamad-abdoun Jul 18, 2025
b62aab7
Corriger les bugs signalés comme critiques
abdessamad-abdoun Jul 18, 2025
6bbce7c
Corriger les bugs signalés comme critiques
abdessamad-abdoun Jul 18, 2025
cf9cbc4
Corriger les bugs signalés comme critiques
abdessamad-abdoun Jul 18, 2025
7472012
Corriger les bugs signalés comme critiques
abdessamad-abdoun Jul 18, 2025
4ed8b3b
Corriger les bugs signalés comme majour
abdessamad-abdoun Jul 21, 2025
d8cec94
Changed from HashMap to ConcurrentHashMap
abdessamad-abdoun Jul 21, 2025
78da786
Corriger les bugs signalés comme securite et majore
abdessamad-abdoun Jul 23, 2025
d85ac9c
Rename field "system" to prevent any misunderstanding/clash with fiel…
abdessamad-abdoun Jul 23, 2025
43f355c
correction Make sure publicly writable directories are used safely here
abdessamad-abdoun Jul 24, 2025
865e38b
Corriger les bugs signalés comme majour
abdessamad-abdoun Jul 24, 2025
80ad3e3
Corriger les bugs signalés comme majour
abdessamad-abdoun Jul 24, 2025
e073266
change LinkedHashMap on HashMap
abdessamad-abdoun Jul 25, 2025
1533281
Strings should not be concatenated using '+' in a loop
abdessamad-abdoun Jul 25, 2025
a6cb302
Corriger les bugs signalés comme majour
abdessamad-abdoun Jul 25, 2025
c5ded56
Corriger les bugs signalés comme mineurs
abdessamad-abdoun Jul 28, 2025
35f94fc
Corriger les bugs signalés comme majour
abdessamad-abdoun Jul 28, 2025
f1aa2f4
correction sonar Make sure publicly writable directories are used saf…
abdessamad-abdoun Jul 29, 2025
d09e102
ajouter TransformerUtils - Méthodes utilitaires statiques réduire la …
abdessamad-abdoun Jul 30, 2025
dc628f0
ajouter ContextManager dédié au contexte d'exécution
abdessamad-abdoun Jul 30, 2025
814f766
Rename field "transform" to prevent any misunderstanding/clash with f…
abdessamad-abdoun Jul 30, 2025
fd7e89e
correction sonar Make sure publicly writable directories are used saf…
abdessamad-abdoun Jul 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 55 additions & 53 deletions src/main/java/fr/inria/corese/core/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

Expand Down Expand Up @@ -122,18 +123,18 @@ public class Graph extends GraphObject implements
// edge Index for RuleEngine where edge are sorted newest first
EdgeManagerIndexer ruleEdgeIndex;
// predefined individual Node such as kg:default named graph
HashMap<String, Node> system;
private ConcurrentHashMap<String, Node> nodeSystem;
// key -> URI Node ; member of graph nodes (subject/object)
Hashtable<String, Node> individual;
private ConcurrentHashMap<String, Node> individual;
// label -> Blank Node ; member of graph nodes (subject/object)
Hashtable<String, Node> blank;
private ConcurrentHashMap<String, Node> nodeBlank;
// Triple Reference Node
Hashtable<String, Node> triple;
private ConcurrentHashMap<String, Node> triple;
// named graph id nodes: key -> named graph id Node (possibly not subject/object
// Node)
Hashtable<String, Node> graph;
private ConcurrentHashMap<String, Node> graph;
// property nodes: label -> property Node (possibly not subject/object Node)
Hashtable<String, Node> property;
private ConcurrentHashMap<String, Node> property;
// key -> Node for value management in external memory
Map<String, Node> vliteral;
ValueResolver values;
Expand Down Expand Up @@ -247,15 +248,15 @@ public Graph(int length) {
// deprecated:
vliteral = Collections.synchronizedMap(new HashMap<>());
// URI Node
individual = new Hashtable<>();
individual = new ConcurrentHashMap<>();
// Blank Node
blank = new Hashtable<>();
nodeBlank = new ConcurrentHashMap<>();
// rdf star triple reference node
triple = new Hashtable<>();
triple = new ConcurrentHashMap<>();
// Named Graph Node
graph = new Hashtable<>();
graph = new ConcurrentHashMap<>();
// Property Node
property = new Hashtable<>();
property = new ConcurrentHashMap<>();

// Index of nodes of named graphs
// Use case: SPARQL Property Path
Expand Down Expand Up @@ -562,22 +563,22 @@ public TreeNode treeNode() {
}

/**
* System Node are predefined such as kg:default Node for default graph They
* nodeSystemNode are predefined such as kg:default Node for default graph They
* have an index but they are not yet stored in any graph table but system
* table They are retrieved by getResource, getNode, getGraph, getProperty
* on demand
*/
void initSystem() {
system = new HashMap<>();
nodeSystem= new ConcurrentHashMap<>();
systemNode = new ArrayList<>();
for (String uri : PREDEFINED) {
Node n = createSystemNode(uri);
system.put(uri, n);
nodeSystem.put(uri, n);
systemNode.add(n);
}
defaultGraph = system.get(Entailment.DEFAULT);
ruleGraph = system.get(Entailment.RULE);
constraintGraph = system.get(Entailment.CONSTRAINT);
defaultGraph = nodeSystem.get(Entailment.DEFAULT);
ruleGraph = nodeSystem.get(Entailment.RULE);
constraintGraph = nodeSystem.get(Entailment.CONSTRAINT);
}

Node createSystemNode(String label) {
Expand All @@ -588,7 +589,7 @@ Node createSystemNode(String label) {
}

Node getSystemNode(String name) {
return system.get(name);
return nodeSystem.get(name);
}

@Override
Expand Down Expand Up @@ -808,7 +809,7 @@ public String toRDF() {
sb.appendPNL("kg:graph ", graph.size());
sb.appendPNL("kg:property ", getSubjectIndex().size());
sb.appendPNL("kg:uri ", individual.size());
sb.appendPNL("kg:bnode ", blank.size());
sb.appendPNL("kg:bnode ", nodeBlank.size());
sb.appendPNL("kg:triple ", triple.size());
sb.appendPNL("kg:literal ", getLiteralNodeManager().size());
sb.appendPNL("kg:nodeManager ", getNodeManager().isEffective());
Expand All @@ -834,7 +835,7 @@ public NodeManager getNodeManager() {
}

/**
* Generate an RDF Graph that describes the KGRAM system and the current RDF
* Generate an RDF Graph that describes the KGRAM nodeSystem and the current RDF
* graph
*/
public Graphable describe() {
Expand Down Expand Up @@ -1526,7 +1527,7 @@ public int nbIndividuals() {
}

public int nbBlanks() {
return blank.size();
return nodeBlank.size();
}

public int nbTriples() {
Expand Down Expand Up @@ -1721,13 +1722,13 @@ public Node getTripleNode(IDatatype dt, boolean create, boolean add) {
}

public Node getLiteralNode(IDatatype dt, boolean create, boolean add) {
String key = getKey(dt);
Node node = getLiteralNode(key, dt);
String keyString = getKey(dt);
Node node = getLiteralNode(keyString, dt);
if (node != null) {
return node;
}
if (create) {
node = createNode(key, dt);
node = createNode(keyString, dt);
if (add) {
addLiteralNode(dt, node);
}
Expand Down Expand Up @@ -1759,7 +1760,7 @@ Node getResource(String key, String name) {
// resource or blank
public boolean isIndividual(Node node) {
return individual.containsKey(getID(node))
|| blank.containsKey(node.getLabel())
|| nodeBlank.containsKey(node.getLabel())
|| triple.containsKey(node.getLabel());
}

Expand Down Expand Up @@ -1790,7 +1791,7 @@ public Node getBlankNode(String name) {
}

public Node getBlankNodeBasic(String name) {
return blank.get(name);
return nodeBlank.get(name);
}

// named graph id may be a bnode
Expand All @@ -1803,7 +1804,7 @@ public Node getTripleNode(String name) {
}

void addBlankNode(IDatatype dt, Node node) {
blank.put(node.getLabel(), node);
nodeBlank.put(node.getLabel(), node);
}

void addTripleNode(IDatatype dt, Node node) {
Expand Down Expand Up @@ -1887,8 +1888,8 @@ Node basicAddResource(String label) {
return node;
}
IDatatype dt = DatatypeMap.createResource(label);
String key = getID(label);
node = createNode(key, dt);
String keyString = getID(label);
node = createNode(keyString, dt);
add(dt, node);
return node;
}
Expand Down Expand Up @@ -2152,21 +2153,21 @@ public Iterable<Edge> iterate(Node s, Node p, Node o, List<Node> from) {

public Iterable<Edge> insert(Node s, Node p, Node o, List<Node> contexts) {
if (contexts == null || contexts.isEmpty()) {
Edge edge = insert(s, p, o);
insert(s, p, o);
} else {
for (Node g : contexts) {
Edge edge = insert(g, s, p, o);
insert(g, s, p, o);
}
}
return emptyEdgeList;
}

public Iterable<Edge> delete(Node s, Node p, Node o, List<Node> contexts) {
if (contexts == null || contexts.isEmpty()) {
List<Edge> edge = delete(s, p, o);
delete(s, p, o);
} else {
for (Node g : contexts) {
List<Edge> edge = delete(g, s, p, o);
delete(g, s, p, o);
}
}
return emptyEdgeList;
Expand Down Expand Up @@ -2274,7 +2275,7 @@ public Iterable<Edge> getAllEdges(Node predicate, Node node, Node node2, int n)
}
}
if (meta.isEmpty()) {
return new ArrayList<Edge>();
return new ArrayList<>();
}
return meta;
}
Expand Down Expand Up @@ -2322,7 +2323,7 @@ public boolean hasEdge(Node node, int i) {
}

public List<Node> getList(Node node) {
List<Node> list = new ArrayList<Node>();
List<Node> list = new ArrayList<>();
list(node, list);
return list;
}
Expand Down Expand Up @@ -2379,11 +2380,11 @@ public ArrayList<IDatatype> reclist(Node node) {
Edge first = getEdge(RDF.FIRST, node, 0);
Edge rest = getEdge(RDF.REST, node, 0);
if (first == null || rest == null) {
return null;
return new ArrayList<>();
}
ArrayList<IDatatype> list = reclist(rest.getNode(1));
if (list == null) {
return null;
return new ArrayList<>();
}
Node val = first.getNode(1);

Expand Down Expand Up @@ -2454,7 +2455,7 @@ public Iterable<Edge> getEdges(Node node, int n) {

// without NodeManager
public Iterable<Edge> getSortedEdgesBasic(Node node, int n) {
MetaIterator<Edge> meta = new MetaIterator<Edge>();
MetaIterator<Edge> meta = new MetaIterator<>();

for (Node pred : getSortedProperties()) {
Iterable<Edge> it = getIndex(n).getEdges(pred, node);
Expand All @@ -2463,7 +2464,7 @@ public Iterable<Edge> getSortedEdgesBasic(Node node, int n) {
}
}
if (meta.isEmpty()) {
return new ArrayList<Edge>();
return new ArrayList<>();
}
return meta;
}
Expand Down Expand Up @@ -2614,14 +2615,14 @@ public Iterable<Node> getNodes() {
}

public Iterable<Node> getBlankNodes() {
return blank.values();
return nodeBlank.values();
}

public Iterable<Node> getTripleNodes() {
return triple.values();
}

public Hashtable<String, Node> getTripleNodeMap() {
public Map<String, Node> getTripleNodeMap() {
return triple;
}

Expand Down Expand Up @@ -2911,7 +2912,7 @@ public boolean compare(Graph g2, boolean isGraph, boolean detail) {
public List<Graph> split() {

if (graph.size() == 1) {
ArrayList<Graph> list = new ArrayList<Graph>();
ArrayList<Graph> list = new ArrayList<>();
list.add(this);
return list;
}
Expand All @@ -2928,7 +2929,7 @@ List<Graph> gSplit() {
g.addEdgeWithNode(ent);
}

ArrayList<Graph> list = new ArrayList<Graph>();
ArrayList<Graph> list = new ArrayList<>();
for (Graph g : map.values()) {
list.add(g);
}
Expand All @@ -2938,7 +2939,7 @@ List<Graph> gSplit() {
}

public List<Edge> getEdgeList(Node n) {
ArrayList<Edge> list = new ArrayList<Edge>();
ArrayList<Edge> list = new ArrayList<>();
for (Edge e : getEdges(n, 0)) {
list.add(e);
}
Expand All @@ -2949,7 +2950,7 @@ public List<Edge> getEdgeList(Node n) {
* Without rule entailment
*/
public List<Edge> getEdgeListSimple(Node n) {
ArrayList<Edge> list = new ArrayList<Edge>();
ArrayList<Edge> list = new ArrayList<>();
for (Edge e : getEdges(n, 0)) {
if (!getProxy().isRule(e)) {
list.add(e);
Expand Down Expand Up @@ -2984,8 +2985,8 @@ public List<Edge> delete(Edge edge) {
}

if (res != null) {
logger.info("" + edge);
logger.info("" + res);
logger.info("{}", edge);
logger.info("{}", res);
deleted(res);
}
return res;
Expand All @@ -3011,8 +3012,8 @@ public List<Edge> delete(Edge edge, List<Constant> from) {
}

if (res != null) {
logger.info("" + edge.getEdgeLabel());
logger.info("" + res);
logger.info("Edge label: {}", edge.getEdgeLabel());
logger.info("Result: {}", res);
deleted(res);
}
return res;
Expand Down Expand Up @@ -3100,7 +3101,7 @@ public void clear() {

void clearNodes() {
individual.clear();
blank.clear();
nodeBlank.clear();
triple.clear();
getLiteralNodeManager().clear();
property.clear();
Expand Down Expand Up @@ -3390,8 +3391,8 @@ public Edge addEdge(Node source, Node predicate, List<Node> list) {
e = fac.create(source, predicate, list);
}

Edge ee = addEdge(e);
return ee;
e = addEdge(e);
return e;
}

/**
Expand Down Expand Up @@ -3536,7 +3537,8 @@ public String reference(Node n) {
// labels
// they should have different ID
if (dt.isDate()) {
if (DatatypeMap.getTZ(dt).equals("Z")) {
Object tz = DatatypeMap.getTZ(dt);
if (tz != null && "Z".equals(tz.toString())) {
return String.format("d%s", n.getIndex());
}
}
Expand Down
Loading