neography get actual node or node id from index - graph

I am using the below to get nodes from an index:
neo.get_node_index('nodes_index', 'type', 'repo')
Which works fine. However, the data returned is a Hash object, as below:
> {"indexed"=>"http://localhost:7474/db/data/index/node/nodes_index/type/repo/12", "outgoing_relationships"=>"http://localhost:7474/db/data/node/12/relationships/out",
> "data"=>{"name"=>"irc-logs"},
> "traverse"=>"http://localhost:7474/db/data/node/12/traverse/{returnType}",
> "all_typed_relationships"=>"http://localhost:7474/db/data/node/12/relationships/all/{-list|&|types}",
> "property"=>"http://localhost:7474/db/data/node/12/properties/{key}",
> "self"=>"http://localhost:7474/db/data/node/12",
> "properties"=>"http://localhost:7474/db/data/node/12/properties",
> "outgoing_typed_relationships"=>"http://localhost:7474/db/data/node/12/relationships/out/{-list|&|types}",
> "incoming_relationships"=>"http://localhost:7474/db/data/node/12/relationships/in",
> "extensions"=>{},
> "create_relationship"=>"http://localhost:7474/db/data/node/12/relationships", "paged_traverse"=>"http://localhost:7474/db/data/node/12/paged/traverse/{returnType}{?pageSize,leaseTime}",
> "all_relationships"=>"http://localhost:7474/db/data/node/12/relationships/all",
> "incoming_typed_relationships"=>"http://localhost:7474/db/data/node/12/relationships/in/{-list|&|types}"}
I would like either the actual node object to be returned, or be able to retrieve the id easily. By id, I am referring to the integer inside http://localhost:7474/db/data/node/12.
I could get it by regex, but this surely isn't the best way?

You could use the 'Phase 2' API to find it as below;
n = Neography::Node.find('nodes_index', 'type', 'repo')
n.neo_id # 12

Related

Best R regex for intercepting a fragment in the middle of a string?

How do I construct a regex to detect the entire middle chunk of a string, so I can gsbu it out? Here's an example of what I'm aiming to do.
MATCH: enter > shop.christopherspenn.com/test > convert
MATCH: enter > shop.christopherspenn.com/page5 > convert
MATCH: enter > shop.christopherspenn.com/ > convert
NO MATCH: enter > christopherspenn.com/test > convert
The goal is to find something like shop.christopherspenn.com/test > and be able to delete it from the string.
I've tried gsub("(shop.christopherspenn.com.*)/ > ","",string) as my call but it's not able to grab the appropriate chunks.
Thanks in advance for any advice!
You can use
string <- c("enter > shop.christopherspenn.com/test > convert","enter > shop.christopherspenn.com/page5 > convert","enter > shop.christopherspenn.com/ > convert","enter > christopherspenn.com/test > convert")
sub('\\bshop\\.christopherspenn\\.com[^>]*>\\s*', '', string)
See the online R demo and the regex demo. Output:
[1] "enter > convert"
[2] "enter > convert"
[3] "enter > convert"
[4] "enter > christopherspenn.com/test > convert"
Details:
\b - a word boundary
shop\.christopherspenn\.com - a shop.christopherspenn.com string
[^>]* - zero or more chars other than >
> - a > char
\s* - zero or more whitespaces.

RSelenium - Storing data in an array

I'm extracting events description from a list of event in my website.
Each event is a href link which goes to another page where we can find the image and the description of the event. I'm trying to store the image url and the description of all events in an array so I used the code below in the end of my loop, but I only get the image and the description of the last event looped:
m<-c(images_of_events)
n<-c( description_of_events)
cc<-remDr$findElement(using = "css", "[class = '_24er']")
cc<-remDr$getPageSource()
page_events<-read_html(cc[[1]][1])
links_events_data=html_nodes(page_events,'._24er > table > tbody > tr > td >
div> div._4dmk > a ')
events_urls<-html_attr(links_events_data,"href")
//the loop of each event
for (i in events_urls) {
remDr$navigate(paste("localhost://www.mywebsite",i,sep=""))
#get image
imagewebElem <- remDr$findElement(using = "class", "scaledImageFitWidth")
images_of_events<-imagewebElem $getElementAttribute("src")
descriptionwebElem <-remDr$findElement(using = "css", "[class = '_63ew']")
descriptionwebElem <-remDr$getPageSource()
page_event_description<-read_html(descriptionwebElem[[1]][1])
events_desc =html_nodes(page_event_description,'._63ew > span')
description_of_events= html_text(events_desc)
m<-c(images_of_events)
n<-c( description_of_events)
}
To save values in array in R you have to
1) create the array/data.frame dta <- data.frame(m=c(),n=c()) and then save to it dta[i,1] <- image_of_events and dta[i,2] <- description_of_evants where i is numeric iterator
2) create the array/data.frame and use rbind to add values like dta <- rbind(dta, data.frame(m=images_of_events, n = description_of_events))

r mongolite - date query

Question
Using the mongolite package in R, how do you query a database for a given date?
Example Data
Consider a test collection with two entries
library(mongolite)
## create dummy data
df <- data.frame(id = c(1,2),
dte = as.POSIXct(c("2015-01-01","2015-01-02")))
> df
id dte
1 1 2015-01-01
2 2 2015-01-02
## insert into database
mong <- mongo(collection = "test", db = "test", url = "mongodb://localhost")
mong$insert(df)
Mongo shell query
To find the entries after a given date I would use
db.test.find({"dte" : {"$gt" : new ISODate("2015-01-01")}})
How can I reproduce this query in R using mongolite?
R attempts
So far I have tried
qry <- paste0('{"dte" : {"$gt" : new ISODate("2015-01-01")}}')
mong$find(qry)
Error: Invalid JSON object: {"dte" : {"$gt" : new ISODate("2015-01-01")}}
qry <- paste0('{"dte" : {"$gt" : "2015-01-01"}}')
mong$find(qry)
Imported 0 records. Simplifying into dataframe...
data frame with 0 columns and 0 rows
qry <- paste0('{"dte" : {"gt" : ', as.POSIXct("2015-01-01"), '}}')
mong$find(qry)
Error: Invalid JSON object: {"dte" : {"gt" : 2015-01-01}}
qry <- paste0('{"dte" : {"gt" : new ISODate("', as.POSIXct("2015-01-01"), '")}}')
mong$find(qry)
Error: Invalid JSON object: {"dte" : {"gt" : new ISODate("2015-01-01")}}
#user2754799 has the correct method, but I've made a couple of small changes so that it answers my question. If they want to edit their answer with this solution I'll accept it.
d <- as.integer(as.POSIXct(strptime("2015-01-01","%Y-%m-%d"))) * 1000
## or more concisely
## d <- as.integer(as.POSIXct("2015-01-01")) * 1000
data <- mong$find(paste0('{"dte":{"$gt": { "$date" : { "$numberLong" : "', d, '" } } } }'))
as this question keeps showing up at the top of my google results when i forget AGAIN how to query dates in mongolite and am too lazy to go find the documentation:
the above Mongodb shell query,
db.test.find({"dte" : {"$gt" : new ISODate("2015-01-01")}})
now translates to
mong$find('{"dte":{"$gt":{"$date":"2015-01-01T00:00:00Z"}}}')
optionally, you can add millis:
mong$find('{"dte":{"$gt":{"$date":"2015-01-01T00:00:00.000Z"}}}')
if you use the wrong datetime format, you get a helpful error message pointing you to the correct format: use ISO8601 format yyyy-mm-ddThh:mm plus timezone, either "Z" or like "+0500"
of course, this is also documented in the mongolite manual
try mattjmorris's answer from github
library(GetoptLong)
datemillis <- as.integer(as.POSIXct("2015-01-01")) * 1000
data <- data_collection$find(qq('{"createdAt":{"$gt": { "$date" : { "$numberLong" : "#{datemillis}" } } } }'))
reference: https://github.com/jeroenooms/mongolite/issues/5#issuecomment-160996514
Prior converting your date by multiplying it with 1000, do this: options(scipen=1000), as the lack of this workaround will affect certain dates.
This is explained here:

order by accented characters in oracle

I have a situation like below:
select p.last_name from person p where user_id = 'mprakash' and contains(last_name , 'fré%') > 0
Result:
FreNormal
Frederic
Frédéric
Frêdéric
result comes as above......accented characters always comes last even if i am giving the search condition with using accented characters 'fré%'
Is there something through which we can get result below:
Frédéric
Frêdéric
FreNormal
Frederic
or if I give search as contains(last_name , 'frê%') > 0
then result comes as below :
Frêdéric
Frédéric
FreNormal
Frederic
and if i search as contains(last_name , 'fre%') > 0 then result would be
FreNormal
Frederic
Frêdéric
Frédéric

Get component of Date / ISODate in mongo

How to get a component like minute from ISODate stored in MongoCollection?
Since you don't specify a language, I'm going to assume you mean JavaScript, as in the shell.
One of the nice features of the shell is it has tab completion. So you can do something like this:
> db.test.insert({x:new Date()});
> var doc = db.test.findOne();
> doc
{
"_id" : ObjectId("4fa131851932655dc45027a9"),
"x" : ISODate("2012-05-02T13:07:17.012Z")
}
> doc.x
ISODate("2012-05-02T13:07:17.012Z")
> doc.x.<TAB><TAB>
doc.x.constructor doc.x.getSeconds( doc.x.getUTCMinutes( doc.x.setHours( doc.x.setUTCHours( doc.x.toLocaleDateString(
doc.x.getDate( doc.x.getTime( doc.x.getUTCMonth( doc.x.setMilliseconds( doc.x.setUTCMilliseconds( doc.x.toLocaleString(
doc.x.getDay( doc.x.getTimezoneOffset( doc.x.getUTCSeconds( doc.x.setMinutes( doc.x.setUTCMinutes( doc.x.toLocaleTimeString(
doc.x.getFullYear( doc.x.getUTCDate( doc.x.getYear( doc.x.setMonth( doc.x.setUTCMonth( doc.x.toString(
doc.x.getHours( doc.x.getUTCDay( doc.x.hasOwnProperty( doc.x.setSeconds( doc.x.setUTCSeconds( doc.x.toTimeString(
doc.x.getMilliseconds( doc.x.getUTCFullYear( doc.x.propertyIsEnumerable( doc.x.setTime( doc.x.setYear( doc.x.toUTCString(
doc.x.getMinutes( doc.x.getUTCHours( doc.x.setDate( doc.x.setUTCDate( doc.x.toDateString( doc.x.tojson(
doc.x.getMonth( doc.x.getUTCMilliseconds( doc.x.setFullYear( doc.x.setUTCFullYear( doc.x.toGMTString( doc.x.valueOf(
What you want is probably:
> doc.x.getSeconds();
17
> doc.x.getMinutes();
7
> doc.x.getHours();
9
> doc.x.getDate();
2
> doc.x.getMonth();
4
> doc.x.getFullYear();
2012

Resources