-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
151 additions
and
39 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
vtl-engine/src/main/java/fr/insee/vtl/provenance/ProvenanceUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package fr.insee.vtl.provenance; | ||
|
||
import fr.insee.vtl.parser.VtlLexer; | ||
import fr.insee.vtl.parser.VtlParser; | ||
import fr.insee.vtl.provenance.model.VTLDataset; | ||
import org.antlr.v4.runtime.CharStreams; | ||
import org.antlr.v4.runtime.CodePointCharStream; | ||
import org.antlr.v4.runtime.CommonTokenStream; | ||
import org.antlr.v4.runtime.tree.ParseTreeWalker; | ||
|
||
import java.util.*; | ||
|
||
public class ProvenanceUtils { | ||
|
||
public static ProvenanceListener getProvenance(String script) { | ||
CodePointCharStream stream = CharStreams.fromString(script); | ||
VtlLexer lexer = new VtlLexer(stream); | ||
VtlParser parser = new VtlParser(new CommonTokenStream(lexer)); | ||
|
||
ProvenanceListener provenanceListener = new ProvenanceListener(); | ||
ParseTreeWalker.DEFAULT.walk(provenanceListener, parser.start()); | ||
|
||
return provenanceListener; | ||
} | ||
|
||
public static void printTree(ProvenanceListener.Node node, String prefix, boolean isLast) { | ||
if (node == null) { | ||
return; | ||
} | ||
|
||
// Print the current node with appropriate formatting | ||
System.out.println(prefix + (isLast ? "└── " : "├── ") + node.name + "\t[ " + node.expression + " ]"); | ||
|
||
// Get the list of parent nodes | ||
Collection<ProvenanceListener.Node> parents = node.parents.values(); | ||
int count = parents.size(); | ||
int index = 0; | ||
|
||
// Recursively print each parent node | ||
for (ProvenanceListener.Node parent : parents) { | ||
printTree(parent, prefix + (isLast ? " " : "│ "), ++index == count); | ||
} | ||
} | ||
|
||
public static List<Object> toBusinessModel(ProvenanceListener listener) { | ||
ArrayList<Object> model = new ArrayList<>(); | ||
LinkedHashMap<String, ProvenanceListener.Node> variables = listener.variables; | ||
variables.values().forEach(node -> { | ||
String name = node.name; | ||
Map<String, ProvenanceListener.Node> parents = node.parents; | ||
VTLDataset vtlDataset = new VTLDataset(name); | ||
model.add(vtlDataset); | ||
}); | ||
return model; | ||
} | ||
|
||
public static void toJSON(ProvenanceListener.Node node) { | ||
|
||
} | ||
|
||
public static void toRDF(ProvenanceListener.Node node) { | ||
|
||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
vtl-engine/src/main/java/fr/insee/vtl/provenance/model/Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package fr.insee.vtl.provenance.model; | ||
|
||
public class Activity { | ||
|
||
private String name; | ||
//TODO: to handle later | ||
//private List<VTLDataset> used; | ||
private String label; | ||
|
||
public Activity(String name, String label) { | ||
this.name = name; | ||
this.label = label; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public void setLabel(String label) { | ||
this.label = label; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
vtl-engine/src/main/java/fr/insee/vtl/provenance/model/VTLDataset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package fr.insee.vtl.provenance.model; | ||
|
||
import java.util.List; | ||
|
||
public class VTLDataset { | ||
|
||
private String name; | ||
private Activity wasGeneratedBy; | ||
private List<VTLDataset> wasDerivedFrom; | ||
|
||
public VTLDataset(String name) { | ||
this.name = name; | ||
} | ||
|
||
public VTLDataset(String name, Activity wasGeneratedBy) { | ||
this.name = name; | ||
this.wasGeneratedBy = wasGeneratedBy; | ||
} | ||
|
||
public VTLDataset(String name, Activity wasGeneratedBy, List<VTLDataset> wasDerivedFrom) { | ||
this.name = name; | ||
this.wasGeneratedBy = wasGeneratedBy; | ||
this.wasDerivedFrom = wasDerivedFrom; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Activity getWasGeneratedBy() { | ||
return wasGeneratedBy; | ||
} | ||
|
||
public void setWasGeneratedBy(Activity wasGeneratedBy) { | ||
this.wasGeneratedBy = wasGeneratedBy; | ||
} | ||
|
||
public List<VTLDataset> getWasDerivedFrom() { | ||
return wasDerivedFrom; | ||
} | ||
|
||
public void setWasDerivedFrom(List<VTLDataset> wasDerivedFrom) { | ||
this.wasDerivedFrom = wasDerivedFrom; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters