I have just cloned the example from https://github.com/spring-guides/gs-accessing-data-neo4j and ran the complete version. It fails with the stack trace below. Is this a fault from my side or is this a problem in the latest release?
Stack trace:
2019-02-18 15:37:39.059 WARN 5145 --- [ main]
org.neo4j.ogm.session.Neo4jSession : Error executing query : Invalid input '|': expected whitespace, comment, a relationship pattern, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ']' (line 1, column 106 (offset: 105))
"MATCH (n:`Person`) WHERE n.`name` = { `name_0` } WITH n RETURN n,[ [ (n)-[r_t1:`TEAMMATE`]-(p1:`Person`) | [ r_t1, p1 ] ] ], ID(n)"
^. Rolling back transaction.
2019-02-18 15:37:39.066 INFO 5145 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-18 15:37:39.071 ERROR 5145 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:821) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:802) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:341) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at hello.Application.main(Application.java:23) [main/:na]
Caused by: org.neo4j.driver.v1.exceptions.ClientException: Invalid input '|': expected whitespace, comment, a relationship pattern, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ']' (line 1, column 106 (offset: 105))
"MATCH (n:`Person`) WHERE n.`name` = { `name_0` } WITH n RETURN n,[ [ (n)-[r_t1:`TEAMMATE`]-(p1:`Person`) | [ r_t1, p1 ] ] ], ID(n)"
^
at org.neo4j.driver.internal.util.ErrorUtil.newNeo4jError(ErrorUtil.java:62) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher.handleFailureMessage(InboundMessageDispatcher.java:137) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.messaging.PackStreamMessageFormatV1$Reader.unpackFailureMessage(PackStreamMessageFormatV1.java:432) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.messaging.PackStreamMessageFormatV1$Reader.read(PackStreamMessageFormatV1.java:396) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.async.inbound.InboundMessageHandler.channelRead0(InboundMessageHandler.java:83) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.async.inbound.InboundMessageHandler.channelRead0(InboundMessageHandler.java:35) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.async.inbound.MessageDecoder.channelRead(MessageDecoder.java:40) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:297) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:413) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1336) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1127) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1162) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4 j.driver.internal.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
It seems that you are running a Neo4j version older than 3.1. The feature Neo4j-OGM uses is pattern comprehension that came in with the 3.1 version (https://neo4j.com/docs/cypher-manual/current/deprecations-additions-removals-compatibility/#cypher-deprecations-additions-removals-3.1).
Related
I am two days new to grok and ELK.
I am struggling with breaking up the log messages based on space and make them appear as different fields in the logstash.
My input pattern is:
2022-02-11 11:57:49 - app - INFO - function_name=add elapsed_time=0.0296 input_params=6_3
I would like to see different fields in the logstash/kibana for function_name, elapsed_time and input_params.
At the moment, I have a following .conf
input{
file{
path => "/path/to/log/file"
start_position => "beginning"
}
}
filter{
grok{
match => {"message" => "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:log-level} %{(?<function_name>[^.]*)\.(?<elapsed_time>[^.]*)\.(?<input>[^.]*)}"}
}
date {
match => ["timestamp", "ISO8601"]
}
function_name {
match => ["function_name", "DATA"]
}
elapsed_time {
match => ["elapsed_time", "BASE16FLOAT"]
}
input {
match => ["input", "DATA"]
}
}
output{
elasticsearch{
hosts => ["localhost:9200"]
index => "math_apis"
}
stdout{codec => rubydebug}
}
But this only produces a following message in logstash
{
"host" => "hostname",
"#timestamp" => 2022-02-11T06:27:49.404Z,
"message" => "2022-02-11 11:57:49 - app - INFO - function_name=add elapsed_time=0.0296 input_params=6_3",
"path" => "path/to/log/file",
"#version" => "1",
"tags" => [
[0] "_grokparsefailure"
]
}
You can use the following pattern:
%{TIMESTAMP_ISO8601:timestamp} - \S+ - %{LOGLEVEL:log_level} - function_name=%{NOTSPACE:function_name} elapsed_time=%{NOTSPACE:elapsed_time} input_params=%{NOTSPACE:input}
Details:
%{TIMESTAMP_ISO8601:timestamp} - timestamp field
- - a literal string
\S+ - any one or more non-whitespace chars
- - a literal string
%{LOGLEVEL:log_level} - LOGLEVEL pattern
- function_name= - a literal string
%{NOTSPACE:function_name} - function_name field of one or more non-whitespace chars
elapsed_time= - space and elapsed_time= string
%{NOTSPACE:elapsed_time} - elapsed_time field of one or more non-whitespace chars
input_params= - literal string
%{NOTSPACE:input} - input field of one or more non-whitespace chars.
See more about Grok patterns here.
Test output:
{
"timestamp": [
[
"2022-02-11 11:57:49"
]
],
"YEAR": [
[
"2022"
]
],
"MONTHNUM": [
[
"02"
]
],
"MONTHDAY": [
[
"11"
]
],
"HOUR": [
[
"11",
null
]
],
"MINUTE": [
[
"57",
null
]
],
"SECOND": [
[
"49"
]
],
"ISO8601_TIMEZONE": [
[
null
]
],
"log_level": [
[
"INFO"
]
],
"function_name": [
[
"add"
]
],
"elapsed_time": [
[
"0.0296"
]
],
"input": [
[
"6_3"
]
]
}
I'm trying to capture and replace a filename like
000035 ZSMS_1.mp3
but also a file like
000035 1OMNA
(I'm basically trying to reorder them so they look like e.g., ZSMS_1(000035).mp3).
I've tried
^(\d+) (.*)(\..*$)?
^(\d+) (.*?)(\..*$)?
What I expect to happen:
000035 ZSMS_1.mp3:
[
{
"groups": [
"000035",
"ZSMS_1",
".mp3"
],
"match": "000035 ZSMS_1.mp3"
}
]
000035 1OMNA:
[
{
"groups": [
"000035",
"1OMNA",
""
],
"match": "000035 1OMNA"
}
]
What happens:
1.
^(\d+) (.*)(\..*$)?
000035 ZSMS_1.mp3:
[
{
"groups": [
"000035",
"ZSMS_1.mp3",
""
],
"match": "000035 ZSMS_1.mp3"
}
]
000035 1OMNA:
[
{
"groups": [
"000035",
"1OMNA",
""
],
"match": "000035 1OMNA"
}
]
^(\d+) (.*?)(\..*$)?
000035 ZSMS_1.mp3:
[
{
"groups": [
"000035",
"",
""
],
"match": "000035 "
}
]
000035 1OMNA:
[
{
"groups": [
"000035",
"",
""
],
"match": "000035 "
}
]
You may use
^(\d+)\h+(.*?)(\.[^.]*)?$
See the regex demo
Details
^ - start of string
(\d+) - Group 1: one or more digits
\h+ - 1+ horizontal whitespaces (for better regex engine cross-compatibility, you may use [^\S\r\n]+ or just [ \t]+ to match a tab or space)
(.*?) - Group 2: zero or more chars other than linebreak chars, as few as possible
(\.[^.]*)? - an optional capturing group #3: a dot and then 0 or more chars other than . as many as possible
$ - end of string.
You could try following regex:
^(\d+)\s*(?:(\w+)?)(?:(\.\w+)?)$
Details:
^ - start of line
(\d+) - Group 1: matches a digit
\s* - separates group 1 and 2
(?:(\w+)?) - Group 2 (optional): matches any word character
(?:(\.\w+)?) - Group 3 (optional): matches the character . and any word character
$ - end of line
Demo
I have this string:
{"TimePeriod": {"Start": "2017-03-01", "End": "2017-04-01"}, "Total": {"UnblendedCost": {"Amount": "2942.25119998", "Unit": "USD"}, "UsageQuantity": {"Amount": "20835", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-04-01", "End": "2017-05-01"}, "Total": {"UnblendedCost": {"Amount": "2982.62609983", "Unit": "USD"}, "UsageQuantity": {"Amount": "21049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-05-01", "End": "2017-06-01"}, "Total": {"UnblendedCost": {"Amount": "1399.04829988", "Unit": "USD"}, "UsageQuantity": {"Amount": "23010", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-06-01", "End": "2017-07-01"}, "Total": {"UnblendedCost": {"Amount": "962.47549987", "Unit": "USD"}, "UsageQuantity": {"Amount": "20049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false}
I am working on a regex to split the above string into multiple records, e.g: each record will look like:
{"TimePeriod": {"Start": "2017-06-01", "End": "2017-07-01"}, "Total": {"UnblendedCost": {"Amount": "962.47549987", "Unit": "USD"}, "UsageQuantity": {"Amount": "20049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false}
My current approach is
(\{\"TimePeriod\":){1}.+(false\}){1}
But this will match the entire string instead of matching each record, I think the solution should be something with the lookahead in regex to ensure the TimePeriod appears just once in the matched string but I don't know how to do it. Any pointers will be appreciated.
*There is no newline between each line, I just put it there for the presentation
This seems work for your need. I just only slightly changed your regex to lazy searching mode.+? from greed .+
(\{\"TimePeriod\":){1}.+?(false\}){1}
Demo
And if some more modification is added, it would be
(\{\"TimePeriod\":).+?(false\})
Another method using lookahead,
(\{\"TimePeriod\":)(?:(?!false).)+(false\})
You may split on the following lookaround:
,(?=\{"TimePeriod":)
Demo
The logic basically says to split at a point where there is a comma immediately followed by the text {"TimePeriod":. Note that this means that there would not be a split at the very start of the text because there is no comma.
Let say my mongodb data store some data with int
num: 850531015931
num: 860338053336
num: 859923992712
Now i would like to query aggregate with regex
those num start with 85, how do i do this with aggregate function?
First you have to convert integer in to string using $substr operator than perform $match funtion using $regex operator
db.collection.aggregate([{$project :{numstring : {$substr :["$number",0,12]}}},{$match :{"numstring":{$regex : /^8.5/}}}])
$substr can be used in a $project stage to convert the num to a string value. You can then have a $match stage with the regex.
Project Stage:
{
$project:{
numAsString: { $substr : ["$num", 0, -1 ] }
}
}
Match Stage:
{
$match : { numAsString: { $regex: /^85.*/ } }
}
Although this can be done by regexes, I would like to suggest an alternate method. The problem with regex is that it wont allow you to index elements. Hence as your collection size increases, your queries will become slower and slower.
You can just go for the basics and do the following checks
{$or: [
{$and: [ {$gte: ['$num', 85] }, {$lte: ['$num', 85] } ]},
{$and: [ {$gte: ['$num', 850] }, {$lte: ['$num', 859] } ]},
{$and: [ {$gte: ['$num', 8500] }, {$lte: ['$num', 8599] } ]},
{$and: [ {$gte: ['$num', 85000] }, {$lte: ['$num', 85999] } ]},
{$and: [ {$gte: ['$num', 850000] }, {$lte: ['$num', 859999] } ]},
{$and: [ {$gte: ['$num', 8500000] }, {$lte: ['$num', 8599999] } ]},
{$and: [ {$gte: ['$num', 85000000] }, {$lte: ['$num', 85999999] } ]},
{$and: [ {$gte: ['$num', 850000000] }, {$lte: ['$num', 859999999] } ]},
{$and: [ {$gte: ['$num', 8500000000] }, {$lte: ['$num', 8599999999] } ]},
{$and: [ {$gte: ['$num', 85000000000] }, {$lte: ['$num', 85999999999] } ]},
]}
Keep doing this till you reach the max possible value in num. Sorry for the ugly code, but it should run faster.
There's no point in using a regular expression in your specific case. As the others already pointed out the conversion to a string can be done using $substr but the all it takes for the filtering is a standard equals comparison:
db.collection.aggregate([{
$addFields: {
"firstTwoDigits": { // create a new field called "firstTwoDigits"
$substr: ["$num", 0, 2] // extract the first two digits only
}
}
}, {
$match: {
"firstTwoDigits": "85" // simple filter
}
}])
Hello I am trying to use the following sdk:
https://github.com/watson-developer-cloud/python-sdk/blob/master/examples/speech_to_text_v1.py
In order to get the text transcription of a wav file as follows:
import json
from os.path import join, dirname
from watson_developer_cloud import SpeechToTextV1
speech_to_text = SpeechToTextV1(
username='XXXXXXXXX',
password='XXXXXXXXX',
x_watson_learning_opt_out=False
)
print(json.dumps(speech_to_text.models(), indent=2))
print('I am using the spanish model for this test')
print(json.dumps(speech_to_text.get_model('es-ES_NarrowbandModel'), indent=2))
with open(join(dirname(__file__), '/Users/Downloads/python-sdk-master/examples/test.wav'),
'rb') as audio_file:
print(json.dumps(speech_to_text.recognize(
audio_file, content_type='audio/wav', timestamps=True,
word_confidence=True),
indent=2))
The problem is that every time that I run the request as follows:
python speech.py
I am getting the same result and it does not matter if I change the name of the file in the parameters I always get:
I am using the spanish model for this test
{
"name": "es-ES_NarrowbandModel",
"language": "es-ES",
"sessions": "https://stream.watsonplatform.net/speech-to-text/api/v1/sessions?model=es-ES_NarrowbandModel",
"url": "https://stream.watsonplatform.net/speech-to-text/api/v1/models/es-ES_NarrowbandModel",
"rate": 8000,
"supported_features": {
"custom_language_model": false,
"speaker_labels": true
},
"description": "Spanish narrowband model."
}
{
"results": [
{
"alternatives": [
{
"word_confidence": [
[
"yeah",
0.361
],
[
"and",
0.867
],
[
"on",
0.448
],
[
"the",
0.243
],
[
"loss",
0.172
],
[
"of",
0.68
],
[
"my",
0.953
],
[
"honor",
0.131
],
[
"and",
0.12
],
[
"sometimes",
0.23
],
[
"platter",
0.659
],
[
"and",
0.339
],
[
"also",
0.337
],
[
"got",
0.227
],
[
"asking",
0.383
],
[
"about",
0.1
],
[
"someone",
0.571
],
[
"economies",
0.144
],
[
"on",
0.146
],
[
"both",
0.093
]
],
"confidence": 0.368,
"transcript": "yeah and on the loss of my honor and sometimes platter and also got asking about someone economies on both ",
"timestamps": [
[
"yeah",
0.18,
0.47
],
[
"and",
0.72,
1.28
],
[
"on",
1.28,
1.41
],
[
"the",
1.41,
1.48
],
[
"loss",
1.48,
1.78
],
[
"of",
1.78,
1.89
],
[
"my",
1.89,
2.04
],
[
"honor",
2.04,
2.37
],
[
"and",
2.37,
2.53
],
[
"sometimes",
2.56,
3.17
],
[
"platter",
3.17,
3.53
],
[
"and",
4.04,
4.17
],
[
"also",
4.17,
4.45
],
[
"got",
4.45,
4.63
],
[
"asking",
4.63,
4.97
],
[
"about",
4.97,
5.18
],
[
"someone",
5.18,
5.45
],
[
"economies",
5.45,
5.97
],
[
"on",
5.97,
6.12
],
[
"both",
6.12,
6.34
]
]
}
],
"final": true
},
{
"alternatives": [
{
"word_confidence": [
[
"even",
0.547
],
[
"in",
0.586
],
[
"the",
0.766
],
[
"planet",
0.276
],
[
"of",
0.131
],
[
"my",
0.188
],
[
So I would like to appreciate support to overcome this task,
You shouldn't need the join(dirname(__file__), if you're specifying a fully qualified file path. If the path of your desired audio file isn't in a relative path, I'd try removing the join, although if that's the problem I'd expect a file not found error.