/** * @param reader the reader * @param writer the writer * @throws IOException Signals that an I/O exception has occurred. * @throws OBOFormatParserException the oBO format parser exception */ public void write(Reader reader, Writer writer) throws IOException { OBOFormatParser parser = new OBOFormatParser(); OBODoc doc = parser.parse(reader); write(doc, writer); }
private void parseDef(Clause cl) { if (stream.consume("\"")) { String def = getParseUntilAdv("\""); cl.setValue(def); parseZeroOrMoreWs(); parseXrefList(cl, true); } else { error("Definitions should always be a quoted string."); } }
/** * @param cl cl * @throws OBOFormatParserException parser exception */ public void parseEOL(Clause cl) { parseZeroOrMoreWs(); parseQualifierBlock(cl); parseHiddenComment(); forceParseNlOrEof(); }
private void parseSubsetdef(Clause cl) { parseIdRef(cl); parseOneOrMoreWs(); if (stream.consume("\"")) { String desc = getParseUntilAdv("\""); cl.addValue(desc); } else { error(""); } parseZeroOrMoreWs(); parseQualifierBlock(cl); parseHiddenComment(); }
protected void parseUnquotedString(Clause cl) { parseZeroOrMoreWs(); String v = getParseUntil("!{"); // strip whitespace from the end - TODO v = removeTrailingWS(v); cl.setValue(v); if (stream.peekCharIs('{')) { parseQualifierBlock(cl); } parseHiddenComment(); }
String t = getParseTag(); Clause cl = new Clause(t); if (parseDeprecatedSynonym(t, cl)) { return cl; error("Could not find tag for: " + t); parseBoolean(cl); } else if (tag == OboFormatTag.TAG_NAME) { parseUnquotedString(cl); } else if (tag == OboFormatTag.TAG_NAMESPACE) { parseIdRef(cl); } else if (tag == OboFormatTag.TAG_ALT_ID) { parseIdRef(cl); } else if (tag == OboFormatTag.TAG_DEF) { parseDef(cl); } else if (tag == OboFormatTag.TAG_COMMENT) { parseUnquotedString(cl); } else if (tag == OboFormatTag.TAG_SUBSET) { parseUnquotedString(cl); } else if (tag == OboFormatTag.TAG_SYNONYM) { parseSynonym(cl); } else if (tag == OboFormatTag.TAG_XREF) { parseDirectXref(cl); } else if (tag == OboFormatTag.TAG_BUILTIN) { parseBoolean(cl); } else if (tag == OboFormatTag.TAG_PROPERTY_VALUE) { parsePropertyValue(cl);
protected void parseHeaderClause(Frame h) { String t = getParseTag(); Clause cl = new Clause(t); OboFormatTag tag = OBOFormatConstants.getTag(t); h.addClause(cl); if (tag == OboFormatTag.TAG_DATA_VERSION) { parseUnquotedString(cl); } else if (tag == OboFormatTag.TAG_FORMAT_VERSION) { parseUnquotedString(cl); } else if (tag == OboFormatTag.TAG_SYNONYMTYPEDEF) { parseSynonymTypedef(cl); } else if (tag == OboFormatTag.TAG_SUBSETDEF) { parseSubsetdef(cl); } else if (tag == OboFormatTag.TAG_DATE) { parseHeaderDate(cl); } else if (tag == OboFormatTag.TAG_PROPERTY_VALUE) { parsePropertyValue(cl); parseZeroOrMoreWs(); parseQualifierBlock(cl); parseHiddenComment(); } else if (tag == OboFormatTag.TAG_IMPORT) { parseImport(cl); } else if (tag == OboFormatTag.TAG_IDSPACE) { parseIdSpace(cl); } else { parseUnquotedString(cl); } }
protected void parseIdLine(Frame f) { String t = getParseTag(); OboFormatTag tag = OBOFormatConstants.getTag(t); if (tag != OboFormatTag.TAG_ID) { error("Expected id tag as first line in frame, but was: " + tag); } Clause cl = new Clause(t); f.addClause(cl); String id = getParseUntil(" !{"); if (id.isEmpty()) { error("Could not find an valid id, id is empty."); } cl.addValue(id); f.setId(id); parseEOL(cl); }
public void parseOBODoc(OBODoc obodoc) throws OBOFormatParserException { Frame h = new Frame(FrameType.HEADER); obodoc.setHeaderFrame(h); parseHeaderFrame(h); parseZeroOrMoreWsOptCmtNl(); while (s.eof() == false) { parseEntityFrame(obodoc); parseZeroOrMoreWsOptCmtNl(); } // set OBO namespace in frames final String defaultOboNamespace = h.getTagValue(OboFormatTag.TAG_DEFAULT_NAMESPACE, String.class); if (defaultOboNamespace != null) { addOboNamespace(obodoc.getTermFrames(), defaultOboNamespace); addOboNamespace(obodoc.getTypedefFrames(), defaultOboNamespace); addOboNamespace(obodoc.getInstanceFrames(), defaultOboNamespace); } }
/** * @param f f * @throws OBOFormatParserException parser exception */ protected void parseTypedefFrameClauseEOL(Frame f) { // comment line: if (stream.peekCharIs('!')) { parseHiddenComment(); forceParseNlOrEof(); } else { Clause cl = parseTypedefFrameClause(); parseEOL(cl); f.addClause(cl); } }
/** * @param f f * @throws OBOFormatParserException parser exception */ protected void parseTermFrameClauseEOL(Frame f) { // comment line: if (stream.peekCharIs('!')) { parseHiddenComment(); forceParseNlOrEof(); } else { Clause cl = parseTermFrameClause(); parseEOL(cl); f.addClause(cl); } }
private boolean parseImport(Clause cl) { parseZeroOrMoreWs(); String v = getParseUntil("!{"); v = removeTrailingWS(v); cl.setValue(v); // parse and ignore annotations for import statements parseZeroOrMoreWs(); if (stream.peekCharIs('{')) { // do noy parse trailing qualifiers. getParseUntilAdv("}"); } parseHiddenComment();// ignore return value, as comments are optional return true; }
protected void validate(OBODoc doc, List<String> danglingReferences, Frame f, String tag, @Nullable OboFormatTag tagconstant, @Nullable Clause c) { if (c != null && OboFormatTag.TERM_FRAMES.contains(tagconstant)) { if (c.getValues().size() > 1) { String error = checkRelation(c.getValue(String.class), tag, f.getId(), doc); if (error != null) { danglingReferences.add(error); } error = checkClassReference(c.getValue2(String.class), tag, f.getId(), doc); if (error != null) { danglingReferences.add(error); } } else { String error = checkClassReference(c.getValue(String.class), tag, f.getId(), doc); if (error != null) { danglingReferences.add(error); } } } }
/** * header-clause ::= format-version-TVP | ... | ... * * @param h header frame * @return false if there are no more header clauses, other wise true * @throws OBOFormatParserException parser exception */ protected boolean parseHeaderClauseNl(Frame h) { parseZeroOrMoreWsOptCmtNl(); if (stream.peekCharIs('[') || stream.eof()) { return false; } parseHeaderClause(h); parseHiddenComment(); forceParseNlOrEof(); return true; }
private void parseHeaderDate(Clause cl) { parseZeroOrMoreWs(); String v = getParseUntil("!"); v = removeTrailingWS(v); try { Date date = OBOFormatConstants.headerDateFormat().parse(v); cl.addValue(date); } catch (ParseException e) { throw new OBOFormatParserException("Could not parse date from string: " + v, e, stream.lineNo, stream.line); } }
private void parseIdRef(Clause cl, boolean optional) { String id = getParseUntil(" !{"); if (!optional && id.length() < 1) { error(""); } cl.addValue(id); }
/** * header-clause ::= format-version-TVP | ... | ... * * @param h header frame * @return false if there are no more header clauses, other wise true * @throws OBOFormatParserException */ protected boolean parseHeaderClauseNl(Frame h) throws OBOFormatParserException { parseZeroOrMoreWsOptCmtNl(); if (s.peekCharIs('[') || s.eof()) { return false; } parseHeaderClause(h); forceParseNlOrEof(); return true; }
/** * Parses a remote URL to an OBODoc * * @param urlstr * @return parsed obo document * @throws IOException * @throws OBOFormatParserException */ public OBODoc parseURL(String urlstr) throws IOException, OBOFormatParserException { URL url = new URL(urlstr); return parse(url); }
protected void forceParseNlOrEof() { parseZeroOrMoreWs(); if (stream.eol()) { stream.advanceLine(); return; } if (stream.eof()) { return; } error("expected newline or end of line but found: " + stream.rest()); }
private boolean parseISODate(Clause cl) { String dateStr = getParseUntil(" !{"); cl.setValue(dateStr); return true; }