How to export neo4j data to csv/json - d3.js

I am using Neo4j Python REST Client and I want to use D3.js for the visualisation of my data.
I am creating the data like this:
gdb = GraphDatabase("http://localhost:7474/db/data/")
alice = gdb.nodes.create(name="Alice",isTeacher=False)
bob = gdb.nodes.create(name="Bob"isTeacher=True)
bob.relationships.create("Knows", alice,strength = 0.4)
Is it possible to transform my data into json/csv in order to use that in D3?
Thanks in advance.

In the current version of neo4jrestclient, there is an option to return the data of a query as a list of rows or as a graph representation. So, you could run a query and use that.
results = gdb.query("MATCH (n)--() RETURN n", data_contents=True)
print(results.rows)
print(results.graph)
Only working for Neo4j 2.0+, though. In future releases, QuerySequence objects like results, will have to_csv() and to_json() helpers.

Related

How to provide parameter input for interaction variable in H2OGradientBoostingEstimator?

I need to use the interaction variable feature of multiclass classification in H2OGradientBoostingEstimator in H2O in Python. I am not sure which parameter to use & how to use that. Can anyone please help me out with this?
Currently, I am using the below code -
pros_gbm = H2OGradientBoostingEstimator(nfolds=0,seed=1234, keep_cross_validation_predictions = False, ntrees=10, max_depth=3, learn_rate=0.01, distribution='multinomial')
hist_gbm = pros_gbm.train(x=predictors, y=target, training_frame=hf_train, validation_frame = hf_test,verbose=True)
GBM inherently creates interactions. You can extract information about feature interactions using the .feature_interaction() extractor method (for an H2O Model). More information is provided in the user guide and the Python docs.
If you want to explicitly add a new column that is the interaction between two numerics, you could create that manually by multiplying the two (or more) columns together to get a new interaction column.
For categorical interactions, there's also the the h2o.interaction() method in Python here to create interaction columns in the data (prior to sending it to the GBM or any algorithm).

How to do string functions on a db table column?

I am trying to do string replace on entries of a column inside a db table. So far, I have reached till here:
$misa = DB::table('mis')->pluck('name');
for($i=0;;$i++)
{
$misa[$i] = substr_replace("$misa[$i]","",-3);
}
The error I am getting is "Undefined offset:443".
P.S. I am not a full-fledged programmer. Only trying to develop a few simple programs for my business. Thank You.
Since it's a collection, use the transform() collection method transform it and avoid this kind of errors. Also, you can just use str_before() method to transform each string:
$misa = DB::table('mis')->pluck('name');
$misa->transform(function($i) {
return str_before($i, ':ut');
});
There are a few ways to make this query prettier and FASTER! The beauty of Laravel is that we have the use of both Eloquent for pretty queries and then Collections to manage the data in a user friendly way. So, first lets clean up the query. You can instead use a DB::Raw select and do all of the string replacing in the query itself like so:
$misa = DB::table('mis')->select(DB::raw("REPLACE(name, ':ut' , '') as name"));
Now, we have a collection containing only the name column, and you've removed ':ut' in your specific case and simply replaced it with an empty string all within the MySQL query itself.
Surprise! That's it. No further php manipulation is required making this process much faster (will be noticeable in large data sets - trust me).
Cheers!

sdn4.0 set resultDataContents graph

I want to use SDN4.0 to visualize by D3 in web application.For example,I want to use the following cypher query to get data:
#Query("MATCH (n:app)-[r:r1]->(m:app) RETURN n.alias,r,m.alias")
Iterable<Map<String, Object>> getAllRelations();
But the httpServer not response the exact data I want.
[{n.alias=A, r=(227)-[r1]->(235), m.alias=B}, ....]
And I want to response r1's properties ,tried r1.* but failed.
From the http://neo4j.com/developer/guide-data-visualization/ there is possible to set resultDataContents to graph(origin as rest)
So Is it any possiblity to set this parameter in SDN4.0 or have other solutions?
Thanks if having any ideas.
SDN is for creating domain rich applications. As such it's not the best tool to use if all you need is a list of properties to represent a graph.
You have a couple of paths as I can see it:
Model your application properly with SDN. Use #NodeEntity on a class called App and create a #Relationship to another App. You can then leverage SDN's repositories to return you a rich domain model which you can then transform (e.g. using DTO's) to the front end if need be.
Use the java Neo4j client, OGM HTTP driver (Undocumented), or if you are happy to completely use Javascript (either from the browser or with meteor or using a NodeJS server) you can just use the Javascript driver and call the database directly.
Either way if you are using D3 I highly recommend you use JSOG to represent your model in the front end.
How do I query for relationship data in spring data neo4j 4?
Above Answer solved my question.By using Neo4jOperations.queryForObjects() under Spring data Neo4j and return path in cypher query.

Best practices for filtering data

The way I see it, when building dynamic charts with filters, each time the user requests filtered data I can
Execute a new MySQL query, and use MySQL to do the filtering.
SELECT date,
SUM(IF( `column` = `condition`, 1, 0)) as count
...
Execute a new MySQL query, and use the server-side language (PHP in my case) to filter.
function getData(condition) {
$resultSet = mysqli_query($link, "SELECT date, column ... ");
$count = 0;
while ($row = mysqli_fetch_assoc($result_set)) {
if ($row['column'] == 'condition') {
$count++;
}
}
}
Initially execute a single MySQL query, pass all the data to the client, and use Javascript & d3 to do the filtering.
I expect the answer is not black-and-white. For instance, if some filter is barely requested, it may not make sense to make the other 95% of users wait for the relevant data, and thus the filter would necessitate a new data call. But I'm really thinking about edge cases - situations where filters are used regularly, but idiosyncratically. At times like this, is it better to put filtering logic in front-end, back-end, or within my database queries?
Generally, if the filtering can be done on the front end, it should be done there. The advantages are:
Doesn't matter if your server goes down
Saves you bandwidth costs
Saves the user waiting for round trip time
The disadvantages are that it may be slower and more complicated than it would be on the backend. However, dependent on data volume, there's a lot of cases (like your examples) where Javascript is plenty good enough. d3 even has a built-in filter function:
//remove anything that isn't cake
d3.selectAll('whatever')
.filter(function(d){return d.type != 'cake'})
.remove()
If you need more complex filtering, such as basic aggregates, you can use Crossfilter (also from Mike Bostock) or the excellent d3+crossfilter wrapper dc.js.

How to retrieve data from SSAS Cube using EDMX?

I was given a cube with all relevant information. Now, I want to query cube and get the data through .net EDMX framework.
Could anyone help me out from where I should start on this? I am really confused and have no idea how to use MDX with edmx.
Is it possible to get the data from Cubes without using MDX using EDMX with LINQ?
It's not possible currently, there is a company who do a version of LinqToMdx, I think they've posted on here before, I don't think they go via the EDMX route exactly.
Standard method in .Net is ADOMD.Net http://msdn.microsoft.com/en-us/library/ms123477.aspx
A nice way of getting data is via the CellSet class, as it contains cells of both the native value and the formatted string for measures:
CellSet adomdCellSet;
using (var adomdConnection = new AdomdConnection())
{
adomdConnection.ConnectionString = "YourConnectionString";
adomdConnection.Open();
var adomdCommand = adomdConnection.CreateCommand();
adomdCommand.CommandText = "YourMDXQuery";
adomdCellSet = adomdCommand.ExecuteCellSet();
}
return adomdCellSet;
Edit: Found the site of the guys who wrote a provider - I can't vouch for them as I've never used it, but it looks interesting http://www.agiledesignllc.com/Products.htm

Resources