Parsing OBO from a String

3 views
Skip to first unread message

Thomas Kappler

unread,
Apr 28, 2010, 5:49:02 AM4/28/10
to OBO-Edit Developers Group
Hi again,

I'd like to parse some OBO that I have as a String in my code (it's
coming over HTTP in a REST app). The current OBO Parser code as
described on the "getting started" page [1] makes this difficult,
because the API needs a path to a file or URL. I need to write my OBO
to a temp file first, which is wasteful.

I tried patching OBOParseEngine to make it a bit more modular by
splitting doParse(String) into the part that creates the
BufferedReader and the part that uses it. That way, one could parse
anything one can instantiate a Reader for, like this:

public OBOSession parse(String obo) throws Exception
{
DefaultOBOParser parser = new DefaultOBOParser();
OBOParseEngine engine = new OBOParseEngine(parser);
parser.startParse();
engine.parse( new BufferedReader(new StringReader(obo)) );
parser.endParse();
return parser.getSession();
}

Unfortunately, the parser needs some namespace state that is
initialized via AbstractParseEngine.parse(String uri) ->
OBOSimpleParser.startFileParse(uri). So more work would be necessary
to break up these pieces.

1. Am I overlooking something?
2. Would there be interest in such a patch?

Thanks,
Thomas

[1] http://wiki.geneontology.org/index.php/OBO-Edit:_OBO_Parser_-_Getting_Started

--
You received this message because you are subscribed to the Google Groups "OBO-Edit Developers Group" group.
To post to this group, send email to obo-ed...@googlegroups.com.
To unsubscribe from this group, send email to obo-edit-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/obo-edit-dev?hl=en.

Chris Mungall

unread,
Apr 28, 2010, 12:53:09 PM4/28/10
to obo-ed...@googlegroups.com

On Apr 28, 2010, at 2:49 AM, Thomas Kappler wrote:

> Hi again,
>
> I'd like to parse some OBO that I have as a String in my code (it's
> coming over HTTP in a REST app). The current OBO Parser code as
> described on the "getting started" page [1] makes this difficult,
> because the API needs a path to a file or URL. I need to write my OBO
> to a temp file first, which is wasteful.
>
> I tried patching OBOParseEngine to make it a bit more modular by
> splitting doParse(String) into the part that creates the
> BufferedReader and the part that uses it. That way, one could parse
> anything one can instantiate a Reader for, like this:
>
> public OBOSession parse(String obo) throws Exception
> {
> DefaultOBOParser parser = new DefaultOBOParser();
> OBOParseEngine engine = new OBOParseEngine(parser);
> parser.startParse();
> engine.parse( new BufferedReader(new StringReader(obo)) );
> parser.endParse();
> return parser.getSession();
> }
>
> Unfortunately, the parser needs some namespace state that is
> initialized via AbstractParseEngine.parse(String uri) ->
> OBOSimpleParser.startFileParse(uri). So more work would be necessary
> to break up these pieces.
>
> 1. Am I overlooking something?

I haven't looked at this section of the code for a while, Amina may be
able to give an answer

> 2. Would there be interest in such a patch?

Potentially yes. I'm mildly hesitant about any changes to the parsers
or writers but now we have a junit test suite things are less likely
to have nasty side-effects. If you write a junit for parsing strings
at the same time, and your patch requires no downstream changes then I
think we'd be more than happy to incorporate it.
Reply all
Reply to author
Forward
0 new messages