I am creating a TokenRegex Rules list. This is what I have:
$STARTING_SEQUENCE = (/start/|/begin/)
{
ruleType: "tokens",
pattern: ([{lemma:$STARTING_SEQUENCE}]),
result: "START"
}
When I compile my code, the compiler gives me this error:
Reading TokensRegex rules from tr.txt
Exception in thread "main" java.lang.RuntimeException: Error parsing file: tr.txt
at edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor.createExtractorFromFile(CoreMapExpressionExtractor.java:258)
at MedicalTranscript.x(MedicalTranscript.java:37)
at MedicalTranscript.main(MedicalTranscript.java:76)
Caused by: java.lang.ClassCastException: edu.stanford.nlp.ling.tokensregex.TokenSequencePattern cannot be cast to java.lang.String
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.CoreMapVarValue(TokenSequenceParser.java:1673)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.AttrValue(TokenSequenceParser.java:1534)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.CoreMapNode(TokenSequenceParser.java:1434)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.NodeBasic(TokenSequenceParser.java:1411)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.NodeGroup(TokenSequenceParser.java:1378)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.NodeDisjConj(TokenSequenceParser.java:1317)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.BracketedNode(TokenSequenceParser.java:1178)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexBasic(TokenSequenceParser.java:884)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexDisjConj(TokenSequenceParser.java:1071)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegex(TokenSequenceParser.java:841)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.BasicValue(TokenSequenceParser.java:383)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.ValueExpression(TokenSequenceParser.java:292)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.Expression(TokenSequenceParser.java:210)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.FieldValue(TokenSequenceParser.java:345)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.CompositeFieldValue(TokenSequenceParser.java:333)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.Rule(TokenSequenceParser.java:122)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.RuleList(TokenSequenceParser.java:107)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.getExpressionExtractor(TokenSequenceParser.java:22)
at edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor.createExtractorFromFile(CoreMapExpressionExtractor.java:254)
... 2 more
What am I doing wrong?
Try
$STARTING_SEQUENCE = "/start|begin/"
Because it is a regular expression for matching the string field lemma, it needs to be a string expressing a normal regular expression over string.
You may also want to do something with the result or use actions to do some annotation:
Example:
{
ruleType: "tokens",
pattern: ([{lemma:$STARTING_SEQUENCE}]),
action: ( Annotate($0, ner, "START") )
}
Related
I'm trying to calculate the time between two events in JMeter using BeanShell PostProcessors.
In the first block, I get the time and store it as a property. This is in one Thread Group.
Then in another Thread Group, I have the second BeanShell block. I get an error which I cannot figure out. I have pasted the error here. Thank you very much for your hints and advice!
Here are the two pieces of BeanShell code:
FIRST POSTPROCESSOR:
//Set the current time to the time_upload variable
long time_upload = prev.getTime(); // get POST Time
props.put("time_upload",(String.valueof(time_upload)));
log.info("Time for Upload is: " + time_upload); // print difference to jmeter.log file
SECOND POSTPROCESSOR:
String no_saved_carts = vars.get("no_saved_carts");
String no_saved_carts_trimmed = no_saved_carts.trim();
String temp_description = vars.get("description");
String temp_description_no_space = temp_description.trim();
String time_upload_local = props.get("time_upload");
if(temp_description_no_space.equals("</") || no_saved_carts_trimmed.equals("No Saved Carts Found")){
vars.put("description","true");
} else{
vars.put("description","false");
//set the time to time_processing based on time_upload
long time_processing_done = prev.getTime(); // get time
long time_upload_long = Long.parseLong(time_upload_local); // get HTTP Sampler 1 execution time from variable
long delta = (time_processing_done - time_upload); // calculate difference
log.info("Time difference is: " + delta + " ms"); // print difference to jmeter.log file
}
The relevant part of the ERROR LOG:
2016/06/03 17:21:22 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``//Set the current time to the time_upload variable long time_upload = prev.getTi . . . '' : Error in method invocation: Static method valueof( long ) not found in class'java.lang.String'
2016/06/03 17:21:22 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``//Set the current time to the time_upload variable long time_upload = prev.getTi . . . '' : Error in method invocation: Static method valueof( long ) not found in class'java.lang.String'
2016/06/03 17:21:22 INFO - jmeter.threads.JMeterThread: Thread is done: Upload Saved Cart Thread Group 1-1
2016/06/03 17:21:22 INFO - jmeter.threads.JMeterThread: Thread finished: Upload Saved Cart Thread Group 1-1
2016/06/03 17:21:22 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String temp_description = vars.get("description"); String no_saved_carts = vars. . . . '' : Typed variable declaration : Method Invocation Long.parseLong
2016/06/03 17:21:22 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String temp_description = vars.get("description"); String no_saved_carts = vars. . . . '' : Typed variable declaration : Method Invocation Long.parseLong
2016/06/03 17:21:26 INFO - jmeter.threads.JMeterThread: Thread is done: Check Upload Status 2-1
You cannot convert long to String using String.valueOf() method, there are following options:
If you still want String just change the line to convert long to String to look like:
props.put("time_upload", Objects.toString(time_upload,null));
Get rid of long -> String and vice versa conversion, props is an usual java.util.Properties class instance so it stores Objects
In first PostProcessor:
long time_upload = prev.getTime();
props.put("time_upload", time_upload);
In second PostProcessor:
long time_upload_long = props.get("time_upload"); // no need to cast from String
You can use bsh.shared namespace to keep any Object - it will be accessible by all Thread Groups
In first PostProcessor:
bsh.shared.time_upload = prev.getTime();
In second PostProcessor:
long time_upload = bsh.shared.time_upload
You can get more informative error messages in jmeter.log file in case of Beanshell script error by surrounding your code with try/catch block like:
try {
//your code here
}
catch (Throwable ex) {
log.error("Something wrong", ex);
throw ex;
}
See How to Use BeanShell: JMeter's Favorite Built-in Component for more JMeter and Beanshell tips and tricks.
hello everyone i wanted to get a text between two regex functions my log file is
11:40:04,202 [ERROR] JobStoreTX - Failed to close Connection
java.sql.SQLException: Already closed.
at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:114)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.closeConnection(JobStoreSupport.java:3579)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.cleanupConnection(JobStoreSupport.java:3555)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3783)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2728)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:264)
11:40:04,202 [ERROR] QuartzSchedulerThread - quartzSchedulerThreadLoop: RuntimeException null
java.lang.reflect.UndeclaredThrowableException
at $Proxy1.rollback(Unknown Source)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.rollbackConnection(JobStoreSupport.java:3604)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3773)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2728)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:264)
Caused by:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at org.quartz.impl.jdbcjobstore.AttributeRestoringConnectionInvocationHandler.invoke(AttributeRestoringConnectionInvocationHandler.java:71)
... 5 more
Caused by:
java.sql.SQLException: Closed Connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)
at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1132)
at org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:368)
at `enter code here`org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:323)
... 10 more
11:41:47,203 [ERROR] JobStoreTX - Failed to close Connection
i want text between two timestamp ie. 11:40:04,202 and 11:40:04,202 which should contain this....
11:40:04,202 [ERROR] JobStoreTX - Failed to close Connection
java.sql.SQLException: Already closed.
at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:114)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.closeConnection(JobStoreSupport.java:3579)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.cleanupConnection(JobStoreSupport.java:3555)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3783)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2728)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:264)
kk let me make it more simple....
static String str1 = "09:37:58,289 This is my small 09:39:18,129 example string which I'm going" +
" to use for pattern matching 09:38:15,835 This is my small example string which" +
" I'm going to use for pattern matching";
String patrn = "((\\d+):(\\d+):(\\d+),(\\d+))";
Pattern p = Pattern.compile(patrn);
Matcher m = p.matcher(str1);
/*while(m.find())
{
for(int i=1;i<m.groupCount();i++)
{
System.out.println(i);
System.out.println(m.group(i));
start = m.start();
System.out.println(start);
end = m.end();
System.out.println(end);
i+=3;
}
}*/
The output which i needed is.....
String1 = 09:37:58,289 This is my small
String2 = 09:39:18,129 example string which I'm going to use for pattern matching
String3 = 09:38:15,835 This is my small example string which I'm going to use for pattern matching
If you want to print only the stacktrace not the date and Log level then you may consider creating your own patter.
Java Doc for log4j pattern
Hi Team,
I'm new to Antlr and I have spent 4 days trying to learn, install, run tutorials and integrate with my IDE. :(
I can run this [tutorial][1] in the Terminal successfully. My goal now is to run the same tutorial in Netbeans with AntlrWorks2 I have cannibalised the Main from [Here][2].
The code compiles, but when I run I get an "java.lang.ExceptionInInitializerError" from init of the Lexer.
1: http://www.antlr.org/wiki/display/ANTLR4/Getting+Started+with+ANTLR+v4
2: http://www.certpal.com/blogs/2011/01/antlr-tutorial-hello-antlr/)
Grammar:
grammar Split;
#header {
package PlayGround.AutoGen;
}
hi : HELLO ID ; // match keyword hello followed by an identifier
ID : [a-z]+ | [A-Z]+; // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
HELLO : '[H|h]ello';
Main:
public class MyMain {
public static void main(String args[]) {
new MyMain().MyAttempt();
}
public void MyAttempt() {
try {
String string = "Hello World";
CharStream charStream = new ANTLRInputStream(string);
/*Line 28*/ SplitLexer lex = new SplitLexer(charStream); /*Line 28*/
org.antlr.v4.runtime.CommonTokenStream tokens;
tokens = new org.antlr.v4.runtime.CommonTokenStream(lex);
SplitParser parser = new SplitParser(tokens);
SplitParser.HiContext split = parser.hi();
String toString = split.toString();
System.out.println(toString);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Error:
run:
Exception in thread "main" java.lang.ExceptionInInitializerError
at PlayGround.MyMain.MyAttempt(MyMain.java:28)
at PlayGround.MyMain.main(MyMain.java:21)
Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 2 (expected 3).
at org.antlr.v4.runtime.atn.ATNSimulator.deserialize(ATNSimulator.java:132)
at PlayGround.AutoGen.SplitLexer.<clinit>(SplitLexer.java:78)
... 2 more
Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 2 (expected 3).
... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
ANSWER: antlr4: ATN version 2 expected 3
It sounds like there might be a version issue. ANTLR generates serialized ATN (augmented transition networks) that have a special format that can change from version to version like 4.0 to 4.1. it's possible that your loading source code generated from the command line in one version and the latest AW2 in NetBeans is trying to read it with a different version.
"Your parser was generated with ANTLR 4.0, but you are trying to execute it with ANTLR 4.1. The most likely cause of this is using ANTLRWorks 2.0 to generate the parser, which internally uses ANTLR 4.0. I'm in the process of releasing ANTLRWorks 2.1 which will correct this mismatch." - 280Z28
Answer is Here
I'm trying to query a file based on the eXist database.
Through a simple function to display the contents of the file, no problem:
XMLResource res = (XMLResource) col.getResource(resourceName);
System.out.println(res.getContent());
But when I try against making a request impossible.
String xQuery = "for $x in doc(\"" + resourceName + "\")." + "return data($x).";
ResourceSet result = service.query(xQuery);
ResourceIterator i = result.getIterator();
I have the following errors:
Exception in thread "main" org.xmldb.api.base.XMLDBException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .
at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:114)
at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:71)
at ExistAccess.main(ExistAccess.java:45)
Caused by: org.apache.xmlrpc.XmlRpcException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
at org.exist.xmldb.RemoteXPathQueryService.query(RemoteXPathQueryService.java:99)
... 2 more
[B#105081caorg.apache.xmlrpc.XmlRpcException: Failed to invoke method queryP in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.StaticXQueryException: exerr:ERROR org.exist.xquery.XPathException: exerr:ERROR err:XPST0003 in line 1, column 58: unexpected token: .
I checked all my .jar file, and all of them are present... I really need help ! Thanks in advance!
Your query:
String xQuery = "for $x in doc(\"" + resourceName + "\")." + "return data($x).";
The core of the error:
err:XPST0003 in line 1, column 58: unexpected token: .
As the error message states, eXist-db recognizes an error with the "."; this period/dot is invalid XQuery. Remove the dot from the query, and you should be fine. The query text itself should look like this:
for $x in doc("/db/mycollection/mydocument.xml") return data($x)
Also, it appears your FLWOR loop is iterating over a single item - the resource. Therefore, the FLWOR is extraneous. You could refactor this as:
data(doc("/db/mycollection/mydocument.xml"))
I think you string concat make this issue, why not try to add a space after ".". Change your code like
String xQuery = "for $x in doc(\"" + resourceName + "\"). " + "return data($x).";
I am getting following exception when trying to run my command line application:
java.lang.ExceptionInInitializerError
at org.hibernate.validator.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:52)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:43)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -2
at java.lang.String.substring(String.java:1937)
at org.hibernate.validator.util.Version.<clinit>(Version.java:39)
... 34 more
Am I doing anything wrong? Please suggest.
This is strange. I pasted the relevant parts of the static initialization block of o.h.v.u.Version in a class with a main and added some poor man's logging traces:
public class VersionTest {
public static void main(String[] args) {
Class clazz = org.hibernate.validator.util.Version.class;
String classFileName = clazz.getSimpleName() + ".class";
System.out.println(String.format("%-16s: %s", "classFileName", classFileName));
String classFilePath = clazz.getCanonicalName().replace('.', '/') + ".class";
System.out.println(String.format("%-16s: %s", "classFilePath", classFilePath));
String pathToThisClass = clazz.getResource(classFileName).toString();
System.out.println(String.format("%-16s: %s", "pathToThisClass", pathToThisClass));
// This is line 39 of `org.hibernate.validator.util.Version`
String pathToManifest = pathToThisClass.substring(0, pathToThisClass.indexOf(classFilePath) - 1)
+ "/META-INF/MANIFEST.MF";
System.out.println(String.format("%-16s: %s", "pathToManifest", pathToManifest));
}
}
And here the output I get when running it:
classFileName : Version.class
classFilePath : org/hibernate/validator/util/Version.class
pathToThisClass : jar:file:/home/pascal/.m2/repository/org/hibernate/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA.jar!/org/hibernate/validator/util/Version.class
pathToManifest : jar:file:/home/pascal/.m2/repository/org/hibernate/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA.jar!/META-INF/MANIFEST.MF
In your case, the StringIndexOutOfBoundsException: String index out of range: -2 suggests that:
pathToThisClass.indexOf( classFilePath )
is returning -1, making the pathToThisClass.substring(0, -2) call indeed erroneous.
And this means that org/hibernate/validator/util/Version.class is somehow not part of the pathToThisClass that you get. I don't have a full explanation but this must be related to the fact that you're using One-Jar.
Could you run the above test class and update your question with the output?
So, as you use One-JAR, the problem probably is in incompatibility between One-JAR and Hibernate Validator. However, in the latest version of One-JAR (0.97) it works fine, therefore use the latest version.