Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asciidoc: document an example for defining labels for types matched by regular expressions in tables #56

Closed
kontext-e opened this issue Jan 17, 2018 · 2 comments
Milestone

Comments

@kontext-e
Copy link
Collaborator

Because in Asciidoc tables, the labels to be assigned are given as attributes and Neo4j does not allow to create lables from properties. Instead jQA capability of using a scripting language has to be used in a concept for doing this.

@kontext-e kontext-e added this to the 1.3.3 milestone Jan 17, 2018
@kontext-e kontext-e self-assigned this Jan 17, 2018
@kontext-e
Copy link
Collaborator Author

When the lables defined like this:
https://github.com/kontext-e/jqassistant-plugins/blob/master/asciidoc/src/test/asciidoc/testfile.adoc

your Asciidoc rule file could contain this snippet:

== Enhance Graph with design information from Architecture Documentation

[[structure:MarkAsciidocTypeRegex]]
[source,cypher,role=concept]
.Mark Asciidoc Table Cells that contain regular expressions for types that have to be marked with given labels.

MATCH
    (a:Asciidoc:Table)-[:BODY]->(body),
    (a)-[:HAS_ATTRIBUTE]->(att:Asciidoc:Attribute)
WHERE
    att.name='label' AND att.value='types'
WITH
    body
MATCH
    (body)-[:CONTAINS_CELLS]->(regexCell:Asciidoc:Cell {colnumber: 0}),
    (body)-[:CONTAINS_CELLS]->(labelCell:Asciidoc:Cell {colnumber: 1})
SET
    regexCell:RegularExpressionCell,
    labelCell:LabelCell
CREATE UNIQUE
    (regexCell)-[:REGEX_FOR_LABEL]->(labelCell)
RETURN
    regexCell, labelCell

[[structure:LabelTypesMatchedByRegex]]
[source,js,role=concept,requiresConcepts="structure:MarkAsciidocTypeRegex"]
.Mark types with labels matched by regex.

var graphDatabaseService = store.getGraphDatabaseService();
// Define the columns returned by the constraint
var columnNames = java.util.Arrays.asList("Type");
// Define the list of rows returned by the constraint
var rows = new java.util.ArrayList();

var result = graphDatabaseService.execute("    MATCH\n" +
                                                   "        (type:Type),\n" +
                                                   "        (regexCell:RegularExpressionCell)-[:REGEX_FOR_LABEL]->(labelCell:LabelCell)\n" +
                                                   "    WHERE\n" +
                                                   "        type.fqn =~ regexCell.text\n" +
                                                   "    RETURN\n" +
                                                   "        type, labelCell.text as label\n");

while(result.hasNext()) {
    var next = result.next();
    var node = next.get("type");
    var label = next.get("label");
    node.addLabel(org.neo4j.graphdb.DynamicLabel.label(label));
    var resultRow = new java.util.HashMap();
    resultRow.put("Class", node);
    rows.add(resultRow);
}

// Return the result
var status = com.buschmais.jqassistant.core.analysis.api.Result.Status.SUCCESS;
new com.buschmais.jqassistant.core.analysis.api.Result(rule, status, severity, columnNames, rows);

@kontext-e
Copy link
Collaborator Author

Rule is added to jqassistant/jqassistant-rules/index.adoc

@kontext-e kontext-e removed their assignment Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants