Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ graphreveal search "10 edges, bipartite, no isolated vertices, 2 components"
graphreveal count "5..6 vertices, connected"
```

```shell
graphreveal count "5 vertices, connected, not (eulerian | planar)"
```

Command `search` will print a list of graphs in [graph6](https://users.cecs.anu.edu.au/~bdm/data/formats.html) format.
You can use [houseofgraphs.org](https://houseofgraphs.org/draw_graph) to visualize them.
Command `count` will simply output the number of specified graphs.
Expand All @@ -60,3 +64,5 @@ Command `count` will simply output the number of specified graphs.

As [N], you can use a simple number or range (e.g., `3-4`, `3..4`, `< 5`, `>= 2`).
You can also negate any property using `!` or `not`.
Use `|` for alternatives (disjunction) and parentheses `()` for grouping.
Conjunction (`,` or `;`) binds tighter than `|`.
2 changes: 1 addition & 1 deletion src/graphreveal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from platformdirs import user_data_dir

__version__ = "1.0.0"
__version__ = "1.1.0"

DATABASE_PATH = os.path.join(
user_data_dir(appname="graphreveal", appauthor="graphreveal"), "graphs.db"
Expand Down
7 changes: 6 additions & 1 deletion src/graphreveal/translator/QueryLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ WHITESPACE: [ \t\r\n]+ -> skip;

INTEGER: [0-9]+;

SEPERATOR: ',' | ';';
AND: ',' | ';';

OR: '|';

LPAREN : '(';
RPAREN : ')';

NOT: 'not' | '!';

Expand Down
18 changes: 13 additions & 5 deletions src/graphreveal/translator/QueryParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ options {
}

query
: expr (SEPERATOR expr)* EOF
: orExpr EOF
;

orExpr
: andExpr (OR andExpr)*
;

andExpr
: expr (AND expr)*
;

expr
: entityProperty # simpleExpr
| boolProperty # simpleExpr
| NOT entityProperty # notExpr
| NOT boolProperty # notExpr
: entityProperty # simpleExpr
| boolProperty # simpleExpr
| NOT expr # notExpr
| LPAREN orExpr RPAREN # parenExpr
;

entityProperty
Expand Down
17 changes: 13 additions & 4 deletions src/graphreveal/translator/QueryTranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@

class QueryTranslator(QueryParserVisitor):
def visitQuery(self, ctx: QueryParser.QueryContext) -> str:
return " AND ".join(
[self.visit(ctx.expr(i)) for i in range(ctx.getChildCount() // 2)]
)
return self.visit(ctx.orExpr())

def visitOrExpr(self, ctx: QueryParser.OrExprContext) -> str:
parts = [self.visit(and_expr_ctx) for and_expr_ctx in ctx.andExpr()]
return " OR ".join(parts)

def visitAndExpr(self, ctx: QueryParser.AndExprContext) -> str:
parts = [self.visit(expr_ctx) for expr_ctx in ctx.expr()]
return " AND ".join(parts)

def visitSimpleExpr(self, ctx: QueryParser.SimpleExprContext):
return self.visitChildren(ctx)

def visitNotExpr(self, ctx: QueryParser.NotExprContext):
return "NOT (" + self.visitChildren(ctx) + ")"
return "NOT (" + self.visit(ctx.expr()) + ")"

def visitParenExpr(self, ctx: QueryParser.ParenExprContext):
return "(" + self.visit(ctx.orExpr()) + ")"

def visitNumEntityProperty(self, ctx: QueryParser.NumEntityPropertyContext):
num = ctx.INTEGER().getText()
Expand Down
337 changes: 173 additions & 164 deletions src/graphreveal/translator/generated/QueryLexer.py

Large diffs are not rendered by default.

Loading