Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Add methods to BEL::Script.parse #62

Open
ncatlett opened this issue Jul 15, 2015 · 2 comments
Open

Add methods to BEL::Script.parse #62

ncatlett opened this issue Jul 15, 2015 · 2 comments
Assignees

Comments

@ncatlett
Copy link
Member

BEL::Script.parse returns an Enumerator with all of the Parameters, Terms, and a Statement. It would be helpful to have shortcut methods to easily get at specific elements like the parsed Term.

For example, given the term: "kin(p(HGNC:AKT1))", I would like to parse the term to identify the outer BEL function (for this example, "kinaseActivity"). To do this, I need to understand exactly what parse will return, and (1) get the Statement, (2) take the Statement.subject - this should be the Term that was parsed, and (3) get the Statement.subject.fx and convert it to its long form.

@abargnesi
Copy link
Member

This is a great idea. We can create a module to hold this API and include it in with BEL::Script::Parser and BEL::Script::IOParser.

Some ideas:

parse(...).parameters

Returns all BEL::Model::Parameter objects as a further Enumerator.

Then similarly:
parse(...).terms
parse(...).statements
parse(...).annotations
parse(...).citations
parse(...).evidence
...

Expanding on the returned Enumerable of parse(...).terms we could provide more specific functions like:

parse(...).terms.with_function(:complex)
parse(...).terms.including_function(:pmod)

Expanding on the returned Enumerable of parse(...).statements we could provide more specific functions like:

parse(...).statements.with_annotation("Cell", "fibroblast")
parse(...).statements.only_nested

Endless fun and possibilities.

@abargnesi
Copy link
Member

abargnesi commented May 3, 2016

Closed. This API will be replaced by bel_parser. The BELParser::ASTFilter allows you to filter types. For example you can find all statements from a BEL Script with:

require 'bel_parser'

include BELParser
statements =
  ASTFilter.new(
    ASTGenerator.new(
      File.open('projects/openbel/bel_parser/corpora/full_abstract1.bel')),
  :simple_statement).each.to_a

# do something with statements

Leaving this open though because ASTFilter will not drill down into every AST to find inner nodes. This limits you, for example, from filtering to all terms in a BEL Script.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants