-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support in mermaid for Filter, Union and improve optional layout
- Loading branch information
1 parent
8746799
commit 448690c
Showing
5 changed files
with
344 additions
and
200 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
...a/swiss/sib/rdf/sparql/examples/mermaid/FindWhichConstantsAreNotOnlyUsedAsPredicates.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,33 @@ | ||
package swiss.sib.rdf.sparql.examples.mermaid; | ||
|
||
import java.util.Set; | ||
|
||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.query.algebra.StatementPattern; | ||
import org.eclipse.rdf4j.query.algebra.Var; | ||
import org.eclipse.rdf4j.query.algebra.helpers.AbstractQueryModelVisitor; | ||
|
||
public final class FindWhichConstantsAreNotOnlyUsedAsPredicates | ||
extends AbstractQueryModelVisitor<RuntimeException> { | ||
private final Set<Value> usedAsNode; | ||
|
||
public FindWhichConstantsAreNotOnlyUsedAsPredicates(Set<Value> usedAsNode) { | ||
this.usedAsNode = usedAsNode; | ||
} | ||
|
||
@Override | ||
public void meet(StatementPattern node) throws RuntimeException { | ||
if (node.getPredicateVar().isConstant()) { | ||
markAsUsed(node.getSubjectVar(), node.getObjectVar()); | ||
} else { | ||
markAsUsed(node.getSubjectVar(), node.getPredicateVar(), node.getObjectVar()); | ||
} | ||
super.meet(node); | ||
} | ||
|
||
private void markAsUsed(Var... vars) { | ||
for (Var v : vars) { | ||
usedAsNode.add(v.getValue()); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/swiss/sib/rdf/sparql/examples/mermaid/NameVariablesAndConstants.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,39 @@ | ||
package swiss.sib.rdf.sparql.examples.mermaid; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.query.algebra.Var; | ||
import org.eclipse.rdf4j.query.algebra.helpers.AbstractQueryModelVisitor; | ||
|
||
public final class NameVariablesAndConstants extends AbstractQueryModelVisitor<RuntimeException> { | ||
private final Map<Value, String> constantKeys; | ||
private final Map<String, String> variableKeys; | ||
private final Map<String, String> anonymousKeys; | ||
|
||
public NameVariablesAndConstants(Map<Value, String> constantKeys, Map<String, String> variableKeys, | ||
Map<String, String> anonymousKeys) { | ||
this.constantKeys = constantKeys; | ||
this.variableKeys = variableKeys; | ||
this.anonymousKeys = anonymousKeys; | ||
} | ||
|
||
@Override | ||
public void meet(Var node) throws RuntimeException { | ||
super.meet(node); | ||
if (node.isAnonymous() && !node.isConstant()) { | ||
if (!anonymousKeys.containsKey(node.getName())) { | ||
String nextId = "a" + (anonymousKeys.size() + 1); | ||
anonymousKeys.put(node.getName(), nextId); | ||
} | ||
} else if (!node.isConstant() && !variableKeys.containsKey(node.getName())) { | ||
String nextId = "v" + (variableKeys.size() + 1); | ||
variableKeys.put(node.getName(), nextId); | ||
|
||
} else if (node.isConstant() && !constantKeys.containsKey(node.getValue())) { | ||
String nextId = "c" + (constantKeys.size() + 1); | ||
constantKeys.put(node.getValue(), nextId); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.