From: Richard G. <ric...@ya...> - 2005-03-07 17:52:48
|
Hi All, I'm trying to execute a tolog query in a TM4J program, and I've encountered a number of problems. Apologies for the length of this mail, but it seemed that whichever way I tried to solve the problem I hit another one which confused me. The query I want to execute, which works fine in the Omnigator, is: TologResultsSet results = queryEval.execute("select $PROTEIN from " + "at-has-go(t-protein-ydl101c : tt-protein, $RESULT : tt-go), " + "$RESULT /= t-go-0000004, " + "$RESULT /= t-go-0000006, " + "at-has-go($PROTEIN : tt-protein, $RESULT : tt-go), " + "$PROTEIN /= t-protein-ydl101c " + "order by $PROTEIN?"); This give an NullPointerException Exception caught: java.lang.NullPointerException java.lang.NullPointerException at org.tm4j.tologx.parser.Variable.equals(Variable.java:31) at java.util.ArrayList.indexOf(ArrayList.java:220) at java.util.ArrayList.contains(ArrayList.java:201) at org.tm4j.tologx.parser.ClauseList.addVariable(ClauseList.java:156) at org.tm4j.tologx.parser.ClauseList.addClause(ClauseList.java:165) at org.tm4j.tologx.parser.TologParser.opclause(TologParser.java:1134) at org.tm4j.tologx.parser.TologParser.clause(TologParser.java:789) at org.tm4j.tologx.parser.TologParser.clauselist(TologParser.java:443) at org.tm4j.tologx.parser.TologParser.query(TologParser.java:498) at org.tm4j.tologx.memory.QueryEvaluatorImpl.prepareQuery(QueryEvaluatorImpl.java:151) at org.tm4j.tologx.memory.QueryEvaluatorImpl.execute(QueryEvaluatorImpl.java:165) at mips.genre.topicmaps.TologBugTests.main(TologBugTests.java:150) I think the source of the problem is the lines: "$RESULT /= t-go-0000004, " + "$RESULT /= t-go-0000006, " + If I comment these out, as below, it works fine, even with the similar "$PROTEIN /= t-protein-ydl101c " still in the query. Both these topics exist in the topic map. so I know that isn't the problem. From the testing I've done with various quries, I get the same excpetion if I use a statement like this in a query, except when it's the last statement (apart from an "order by"), so could there be a problem with the comma after a topic id, used in this way is parsed? TologResultsSet results = queryEval.execute("select $PROTEIN from " + "at-has-go(t-protein-ydl101c : tt-protein, $RESULT : tt-go), " + //"$RESULT /= t-go-0000004, " + //"$RESULT /= t-go-0000006, " + "at-has-go($PROTEIN : tt-protein, $RESULT : tt-go), " + "$PROTEIN /= t-protein-ydl101c " + "order by $PROTEIN?"); Having encountered this problem, I looked for other ways to formulate the query. First I tried using "not" statements with an "=", instead of using the "/=". TologResultsSet results = queryEval.execute("select $PROTEIN from " + "at-has-go(t-protein-ydl101c : tt-protein, $RESULT : tt-go), " + "not($RESULT = t-go-0000004), " + "not($RESULT = t-go-0000006), " + "at-has-go($PROTEIN : tt-protein, $RESULT : tt-go), " + "$PROTEIN /= t-protein-ydl101c " + "order by $PROTEIN?"); Again, this query works fine in the omnigator, but I get an excpetion with TM4J. Exception caught: org.tm4j.tologx.TologParserException: Error parsing query string. org.tm4j.tologx.TologParserException: Error parsing query string. at org.tm4j.tologx.memory.QueryEvaluatorImpl.prepareQuery(QueryEvaluatorImpl.java:155) at org.tm4j.tologx.memory.QueryEvaluatorImpl.execute(QueryEvaluatorImpl.java:165) at mips.genre.topicmaps.TologBugTests.main(TologBugTests.java:150) Caused by: line 1:103: unexpected char: '=' at org.tm4j.tologx.parser.TologLexer.nextToken(TologLexer.java:212) at antlr.TokenBuffer.fill(TokenBuffer.java:69) at antlr.TokenBuffer.LA(TokenBuffer.java:80) at antlr.LLkParser.LA(LLkParser.java:52) at antlr.Parser.match(Parser.java:212) at org.tm4j.tologx.parser.TologParser.clause(TologParser.java:776) at org.tm4j.tologx.parser.TologParser.clauselist(TologParser.java:437) at org.tm4j.tologx.parser.TologParser.notclause(TologParser.java:851) at org.tm4j.tologx.parser.TologParser.clause(TologParser.java:734) at org.tm4j.tologx.parser.TologParser.clauselist(TologParser.java:443) at org.tm4j.tologx.parser.TologParser.query(TologParser.java:498) at org.tm4j.tologx.memory.QueryEvaluatorImpl.prepareQuery(QueryEvaluatorImpl.java:151) ... 2 more It seems the query parser is taking exception (excuse the pun) to the "=". I did some more testing with other query variations using the "=" comparator, such as TologResultsSet results = queryEval.execute("select $PROTEIN from " + "at-has-go(t-protein-ydl101c : tt-protein, $RESULT : tt-go), " + "$RESULT = t-go-0006468, " + "at-has-go($PROTEIN : tt-protein, $RESULT : tt-go), " + "$PROTEIN /= t-protein-ydl101c " + "order by $PROTEIN?"); String[] replacements = {"GO:0006468"}; TologResultsSet results = queryEval.execute( "select $PROTEIN from " + "at-has-go(t-protein-ydl101c : tt-protein, $RESULT : tt-go), " + "topic-name($GO1, $GO1_NAME), " + "value($GO1_NAME, %1), " + "$RESULT = $GO1, " + "at-has-go($PROTEIN : tt-protein, $RESULT : tt-go), " + "$PROTEIN /= t-protein-ydl101c" + "order by $PROTEIN?", replacements); These give the same excpetion. I next looked at getting topics by name, and going back to using the "/=" comparator. TologResultsSet results = queryEval.execute( "select $PROTEIN from " + "at-has-go(t-protein-ydl101c : tt-protein, $RESULT : tt-go), " + "topic-name($GO1, $GO1_NAME), " + "value($GO1_NAME, \"GO:0000004\"), " + "topic-name($GO2, $GO2_NAME), " + "value($GO2_NAME, \"GO:0000006\"), " + "$RESULT /= $GO1, " + "$RESULT /= $GO2, " + "at-has-go($PROTEIN : tt-protein, $RESULT : tt-go), " + "$PROTEIN /= t-protein-ydl101c " + "order by $PROTEIN?"); Again, this query worked fine in the omnigator, but I got an exception with TM4J. Exception caught: org.tm4j.tologx.TologParserException: Error parsing query string. org.tm4j.tologx.TologParserException: Error parsing query string. at org.tm4j.tologx.memory.QueryEvaluatorImpl.prepareQuery(QueryEvaluatorImpl.java:155) at org.tm4j.tologx.memory.QueryEvaluatorImpl.execute(QueryEvaluatorImpl.java:165) at mips.genre.topicmaps.TologBugTests.main(TologBugTests.java:120) Caused by: line 1:128: unexpected token: "GO:0000004" at org.tm4j.tologx.parser.TologParser.expr(TologParser.java:1244) at org.tm4j.tologx.parser.TologParser.pair(TologParser.java:1151) at org.tm4j.tologx.parser.TologParser.predclause(TologParser.java:1085) at org.tm4j.tologx.parser.TologParser.clause(TologParser.java:786) at org.tm4j.tologx.parser.TologParser.clauselist(TologParser.java:443) at org.tm4j.tologx.parser.TologParser.query(TologParser.java:498) at org.tm4j.tologx.memory.QueryEvaluatorImpl.prepareQuery(QueryEvaluatorImpl.java:151) ... 2 more I next tried to pass the topic names in from an array. Because I ultimately want to repeat the query with other protein topic ID's, I tried to pass this in from the array as well. String[] replacements = {"t-protein-ydl101c", "GO:0000004", "GO:0000006"}; TologResultsSet results = queryEval.execute( "select $PROTEIN from " + "at-has-go(%1 : tt-protein, $RESULT : tt-go), " + "topic-name($GO1, $GO1_NAME), " + "value($GO1_NAME, %2), " + "topic-name($GO2, $GO2_NAME), " + "value($GO2_NAME, %3), " + "$RESULT /= $GO1, " + "$RESULT /= $GO2, " + "at-has-go($PROTEIN : tt-protein, $RESULT : tt-go), " + "$PROTEIN /= %1 " + "order by $PROTEIN?", replacements); This gives yet another excpetion. Exception caught: org.tm4j.tologx.TologProcessingException: Type mismatch in replacement %1. A Topic was expected. org.tm4j.tologx.TologProcessingException: Type mismatch in replacement %1. A Topic was expected. at org.tm4j.tologx.parser.ClauseList.doReplacement(ClauseList.java:216) at org.tm4j.tologx.parser.TologQuery.execute(TologQuery.java:154) at org.tm4j.tologx.memory.PreparedQueryImpl.execute(PreparedQueryImpl.java:56) at org.tm4j.tologx.memory.QueryEvaluatorImpl.execute(QueryEvaluatorImpl.java:174) at mips.genre.topicmaps.TologBugTests.main(TologBugTests.java:119) I did find away around it, creating a string variable to hold the topic ID, and concatenating this into the query string. String[] replacements = {"GO:0000004", "GO:0000006"}; String proteinID = "t-protein-ydl101c"; TologResultsSet results = queryEval.execute( "select $PROTEIN from " + "at-has-go(" + proteinID + " : tt-protein, $RESULT : tt-go), " + "topic-name($GO1, $GO1_NAME), " + "value($GO1_NAME, %2), " + "topic-name($GO2, $GO2_NAME), " + "value($GO2_NAME, %3), " + "$RESULT /= $GO1, " + "$RESULT /= $GO2, " + "at-has-go($PROTEIN : tt-protein, $RESULT : tt-go), " + "$PROTEIN /= " + proteinID + " " + "order by $PROTEIN?", replacements); This now works, and gives me the functionality I want, but I've no idea why the earleir queries gave the exceptions they did. Has anyone else experienced anything like these problems, or can anyone explain them? I'm really confused by these, especially when the queries worked in the omnigator, so if anyone can offer an explanation, even "tm4j bug" (sorry, Kal) I'd be grateful. Cheers, Richard. Send instant messages to your online friends http://uk.messenger.yahoo.com |