Code Monkey home page Code Monkey logo

yarspg's Introduction

YARS-PG grammar

GitHub Actions Workflow Status GitHub Release DOI

The YARS-PG serialization is designed for property graphs (but not only):

  • YARS-PG supports all the features allowed by the current database systems based on the property graph data model,
  • YARS-PG provides a simple syntax with a reduced number of extra characters,
  • YARS-PG is inspired by the syntax used by popular graph query languages (e.g. Cypher and GQL) to encode the structure of a property graph (i.e. nodes, edges, and properties).

The YARS-PG grammar is written in ANTLR4. If you prefer Extended Backus-Naur Form (EBNF) notation, you can also see YARS-PG grammar in EBNF. See examples to get familiar with the YARS-PG syntax.

Parsers

The YARS-PG parsers are available in the parsers. Currently, there are parsers for the following languages:

If you want to help build YARS-PG parsers for other languages, please follow the ANTLR4 documentation and create a pull request.

See the README.md file in each parser directory for more details. Ready-to-use parsers are also available in the Assets section in Releases.

Testing grammar

Run tests on files in yarspg/examples:

mvn clean test

This project is based on the ANTLR grammars-v4 project.

Contribution

Would you like to improve this project? Great! We are waiting for your help and suggestions. If you are new to open source contributions, read How to Contribute to Open Source.

License

Distributed under BSD 3-Clause License.

yarspg's People

Contributors

dependabot[bot] avatar domel avatar lszeremeta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yarspg's Issues

Updated EBNF

I have an EBNF parser generator and am working with the grammar and came up with some issues. I've included an updated grammar, which I believe does what you want.

Whitespace is ignored in EBNF, so you can't rely on newlines for grouping (e.g., metadata). So, for example, I've changed this to the following:

[6]   metadata  ::= "-" ((pn_local pname) | (IRI ":")) (STRING | IRI)

Also, for a Parser Expression Grammar, order of productions is significant, so parsing TIMESTAMP before DATE becomes significant.

[1]   yarspg  ::= statement+
[2]   statement ::= node | edge | prefix_directive | metadata | node_schema | edge_schema | section
[3]   prefix_directive  ::= pname IRI
[4]   pname ::= ":" ALNUM_PLUS ":"
[5]   pn_local  ::= ALNUM_PLUS
[6]   metadata  ::= "-" ((pn_local pname) | (IRI ":")) (STRING | IRI)
[6a]  graph_name ::= STRING
[7]   annotation  ::= string_annotation | rdf_annotation
[8]   string_annotation ::= STRING ":" STRING
[9]   rdf_annotation  ::= ((pn_local pname) | (IRI ":")) (STRING | IRI)
[10]  annotations_list  ::= "+" annotation ("," annotation)*
[11]  props_list  ::= "[" prop ("," prop)* "]"
[12]  graphs_list ::= "/" graph_name ("," graph_name)* "/"
[13]  node  ::= "<" node_id ">" ("{" node_label ("," node_label)* "}")? props_list? graphs_list? annotations_list?
[14]  edge  ::= directed | undirected
[15]  section ::= "%" SECTION_NAME
[16]  directed  ::= "(" node_id ")" "-" ("<" edge_id ">")? "{" edge_label "}" props_list? "->" "(" node_id ")" graphs_list? annotations_list?
[17]  undirected  ::= "(" node_id ")" "-" ("<" edge_id ">")? "{" edge_label "}" props_list? "-" "(" node_id ")" graphs_list? annotations_list?
[18]  node_id ::= STRING
[19]  node_label  ::= STRING
[20]  prop  ::= key ":" value
[21]  edge_id ::= STRING
[22]  edge_label  ::= STRING
[23]  key ::= STRING
[24]  value ::= primitive_value | complex_value
[25]  primitive_value ::= STRING | DATETYPE | NUMBER | BOOL | "null"
[26]  complex_value ::= set | list | struct
[27]  set ::= "{" (primitive_value | set) ("," (primitive_value | set))* "}"
[28]  list  ::= "[" (primitive_value | list) ("," (primitive_value | list))* "]"
[29]  struct  ::= "{" key ":" (primitive_value | struct) ("," key ":" (primitive_value | struct))* "}"
[30]  node_schema ::= "S" ("{" node_label ("," node_label)* "}") props_list_schema? graphs_list? annotations_list?
[31]  props_list_schema ::= "[" prop_schema ("," prop_schema)* "]"
[32]  prop_schema ::= key ":" value_schema
[33]  value_schema  ::= primitive_value_schema | complex_value_schema
[34]  primitive_value_schema  ::= "Decimal" | "SmallInt" | "Integer" | "BigInt" | "Float" | "Real" | "Double" | "Bool" | "Null" | "String" | "Date" | "Timestamp" | "Time"
[35]  complex_value_schema  ::= set_schema | list_schema | struct_schema
[36]  set_schema  ::= "Set" "(" (primitive_value_schema | set_schema) ")"
[37]  list_schema ::= "List" "(" (primitive_value_schema | list_schema) ")"
[38]  struct_schema ::= "Struct" "(" (primitive_value_schema | struct_schema) ")"
[39]  edge_schema ::= directed_schema | undirected_schema
[40]  directed_schema ::= "S" ("(" node_label ")")? "-" "{" edge_label "}" props_list_schema? "->" ("(" node_label ")")?
[41]  undirected_schema ::= "S" ("(" node_label ")")? "-" "{" edge_label "}" props_list_schema? "-" ("(" node_label ")")?
[42]  SECTION_NAME  ::= "METADATA" | "NODE SCHEMAS" | "EDGE SCHEMAS" | "NODES" | "EDGES"
[43]  COMMENT ::= "#" ([^#xd#xa#xc])*
[44]  STRING  ::= STRING_LITERAL_QUOTE
[45]  NUMBER  ::= SIGN? ([0-9])+ "."? ([0-9])*
[46]  BOOL  ::= "true" | "false"
[47]  STRING_LITERAL_QUOTE  ::= '"' ([^"#xd#xa] | "'" | '"')* '"'
[48]  ALNUM_PLUS  ::= PN_CHARS_BASE ((PN_CHARS | ".")* PN_CHARS)?
[49]  IRI ::= "<" (PN_CHARS | "." | ":" | "/" | "\" | "#" | "@" | "%" | "&" | UCHAR)* ">"
[50]  PN_CHARS  ::= PN_CHARS_U | [-0-9#xB7#x0300-#x036F#x203F-#x2040]
[51]  PN_CHARS_U  ::= PN_CHARS_BASE | "_"
[52]  DATETYPE  ::= TIMESTAMP | DATE | TIME
[53]  DATE  ::= [0-9] [0-9] [0-9] [0-9] "-" [0-9] [0-9] "-" [0-9] [0-9]
[54]  TIME  ::= [0-9] [0-9] ":" [0-9] [0-9] ":" [0-9] [0-9] TIMEZONE?
[55]  TIMEZONE  ::= SIGN? [0-9] [0-9] ":" [0-9] [0-9]
[56]  TIMESTAMP ::= DATE "T" TIME
[57]  SIGN  ::= "+" | "-"
[58]  UCHAR ::= ("u" | "U" HEX HEX HEX HEX) HEX HEX HEX HEX
[59]  PN_CHARS_BASE ::= [A-Za-z0-9#xC0-#xD6#xD8-#xF6#xF8-#x2FF#x370-#x37D#x37F-#x1FFF#x200C-#x200D#x2070-#x218F#x2C00-#x2FEF#x3001-#xD7FF#xF900-#xFDCF#xFDF0-#xFFFD]
[60]  HEX ::= [0-9A-Fa-f]
[61]  WS  ::= ([#x20#x9#xa] | COMMENT)+

There may be some issues with some of the terminal definitions, as I don't necessarily parse based on these precise definitions.

FYI, the EBNF definition I use is described in the Ruby Gem, and more specifically at https://raw.githubusercontent.com/dryruby/ebnf/develop/etc/ebnf.ebnf. It's a bit more formal than that described in the XML spec.

The ebnf gem can be used to create parsers (either LL(1) or PEG) from W3C EBNF definitions.

Unable to load 1.17 version of antlr4test

I have tried to run mvn clean test command and after that I saw error below.
Solution is to switch to <antlr4test-maven-plugin.version>1.11</antlr4test-maven-plugin.version>

[ERROR] Failed to execute goal com.khubla.antlr:antlr4test-maven-plugin:1.17:test (default) on project yarspg: Execution default of goal com.khubla.antlr:antlr4test-maven-plugin:1.17:test failed: Unable to load the mojo 'test' in the plugin 'com.khubla.antlr:antlr4test-maven-plugin:1.17' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: com/khubla/antlr/antlr4test/GrammarTestMojo has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>com.khubla.antlr:antlr4test-maven-plugin:1.17
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/hubsup/.m2/repository/com/khubla/antlr/antlr4test-maven-plugin/1.17/antlr4test-maven-plugin-1.17.jar
[ERROR] urls[1] = file:/home/hubsup/.m2/repository/org/antlr/antlr4-runtime/4.9.1/antlr4-runtime-4.9.1.jar
[ERROR] urls[2] = file:/home/hubsup/.m2/repository/org/antlr/antlr4/4.9.1/antlr4-4.9.1.jar
[ERROR] urls[3] = file:/home/hubsup/.m2/repository/org/antlr/antlr-runtime/3.5.2/antlr-runtime-3.5.2.jar
[ERROR] urls[4] = file:/home/hubsup/.m2/repository/org/antlr/ST4/4.3/ST4-4.3.jar
[ERROR] urls[5] = file:/home/hubsup/.m2/repository/org/abego/treelayout/org.abego.treelayout.core/1.0.3/org.abego.treelayout.core-1.0.3.jar
[ERROR] urls[6] = file:/home/hubsup/.m2/repository/org/glassfish/javax.json/1.0.4/javax.json-1.0.4.jar
[ERROR] urls[7] = file:/home/hubsup/.m2/repository/com/ibm/icu/icu4j/61.1/icu4j-61.1.jar
[ERROR] urls[8] = file:/home/hubsup/.m2/repository/commons-io/commons-io/2.8.0/commons-io-2.8.0.jar
[ERROR] urls[9] = file:/home/hubsup/.m2/repository/org/codehaus/plexus/plexus-utils/3.3.0/plexus-utils-3.3.0.jar
[ERROR] urls[10] = file:/home/hubsup/.m2/repository/org/bitbucket/cowwoc/diff-match-patch/1.2/diff-match-patch-1.2.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :yarspg

Broaden range of allowed identifiers

YARS-PG 3.0.0 allowed arbitrary strings as node identifiers. With YARS-PG 4.0.0 this has been limited to ALNUMPLUS:

node_id
    : ALNUMPLUS   
    ;

ALNUMPLUS
    : [a-zA-Z_][a-zA-Z0-9_]*

I'd support arbitrary quoted strings

node_id
    : ALNUMPLUS
    | STR   
    ;

or at least numbers

node_id
    : ALNUMPLUS
    | UNSIGNED_INT   
    ;

Extend README with related works and applications

The README file should include some information about motivation, related works, and application of YARS-PG. So far I found
http://dx.doi.org/10.13140/RG.2.2.35773.92640 (the original poster from 2019, describing YARS-PG 3.0.0?). https://github.com/gkellogg/yarspg (seems to use version 3.0.0 as well), and https://doi.org/10.6084/m9.figshare.25139015.v1 (some actual data in YARS-PG). Are there more applications and examples to try out and test against?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.