Using a new KeySpaces in Titan Cassandra and persisting data - graph-databases

I have just started using Titan over Cassandra. I am new to Titan and also new to the the Graph Database Concept. Just followed the instructions on github and wiki.
Configuration conf = new BaseConfiguration();
conf.setProperty("storage.backend", "cassandra");
conf.setProperty("storage.hostname", "127.0.0.1");
TitanGraph g = TitanFactory.open(conf);
This is how I opened the graph.
I understand that the default key space is titan. I created some nodes and relations in the default key space. I did Indexing on the vertex and queried the nodes and were able to iterate through the results.
Now my questions -
1) How do I set a new Key Space ?
I tried using the property
conf.setProperty("storage.keyspace ", "newkeyspace");
Unfortunately, when I checked the cassandra keyspaces, I could only find titan. There was no keyspace by the name newkeyspace. What could be the reason?
2) How do I persist a graph have been created?
for example,
g.createKeyIndex("name", Vertex.class);
Vertex juno = g.addVertex(null);
juno.setProperty("name", "juno");
juno.setProperty("type", "node");
Vertex juno1 = g.addVertex(null);
juno1.setProperty("name", "juno");
juno1.setProperty("type", "node1");
This is one sample graph. Once I issue a query of the form
Iterator<Vertex> junoIterator = g.getVertices("name", "juno")
.iterator();
while (junoIterator.hasNext()) {
Vertex vertex = (Vertex) junoIterator.next();
System.out.println(vertex.getProperty("type"));
}
My expected result is
node
node1
The same query should work fine once I comment the following segment -
/*g.createKeyIndex("name", Vertex.class);
Vertex juno = g.addVertex(null);
juno.setProperty("name", "juno");
juno.setProperty("type", "node");
Vertex juno1 = g.addVertex(null);
juno1.setProperty("name", "juno");
juno1.setProperty("type", "node1");*/
Here, what I believe is that the nodes, relations and index already have been built and is persisted in some datastore. Am I of the wrong belief?
Please advice.

I have figured out the issue. Was just a matter of commit.
A single line g.commit(); solves it all.

To create a new Titan Table(Keyspace in cassandra) in please use the property :
set("storage.cassandra.keyspace","TitanTest")
the whole command wud be like :
graph = TitanFactory.build().
set("storage.backend","cassandra").
set("storage.hostname","127.0.0.1").set("index.search.backend","elasticsearch").set("storage.cassandra.astyanax.cluster-name","Test Cluster").set("storage.cassandra.keyspace","TitanTest").set("cache.db-cache","true").open();

Related

Best way to mass-insert Edges into ArangoDB?

I'm writing a python converter for Neo4J to ArangoDB and expect +10k Nodes to be imported.
The converter for the Nodes is somewhat trivial but the creator of that database has a rather custom key-setting so I can't export his keys from his Neo4J instance but I know the name of the PK-Field.
That give me multiple approaches to set the Edges. Right now I'm getting the correct _key of the nodes in the ArangoDB-Collection of the from/to and insert a new edge (code below).
Theoretically I could write the AQL-Statements that just insert these edges, but is that more efficient?
Is there a better approach than my current one?
def getLinkN4jNodes(au,relationships,keyname,col,ecol):
for relationship in relationships:
startnode = relationship.start_node
endnode= relationship.end_node
sn_key=dict(startnode)[keyname]
en_key=dict(endnode)[keyname]
a_sn = au.getNodesFromDB(col,keyname,sn_key)# f"FOR doc IN {col} FILTER doc.`{keyname}`== '{sn_key}' RETURN doc"
a_en = au.getNodesFromDB(col,keyname,en_key)
newedge={
"_key":a_sn["_key"]+'_'+a_en["_key"],
"_from":a_sn["_key"],
"_to": a_en["_key"]
}
ecol.insert(newedge)

How to get data from an upstream node in maya?

I have a maya node myNode, which creates a shadeNode, which inMesh attribute is connected to shapeNode.outMesh and has an attribute distance.
myNode.outMesh -> shapeNode.inMesh
myNode.distance = 10
Then i have a command, which works on the shape node, but requires the distance argument, which it does by iterating over the inMesh connections:
MPlugArray meshConnections;
MPlug inMeshPlug = depNodeFn.findPlug("inMesh");
inMeshPlug.connectedTo(meshConnections, true, false); // in connections
bool node_found = false;
for(uint i = 0; i < numConnections; i++) {
MPlug remotePlug = meshConnections[i];
myNode = remotePlug.node();
if(MFnDependencyNode(myNode ).typeName() == "myNode") {
node_found = true;
break;
}
}
MFnDependencyNode myDepNode(myNode);
MPlug distancePlug = myDepNode.findPlug("distance");
Now i get a problem, when applying another node (of another type) to myShape, because the dependency graph now looks like this:
myNode.outMesh -> myOtherNode.inMesh
myOtherNode.outMesh -> shapeNode.inMesh
myNode.distance = 10
I tried to remove the check for typeName() == "myNode", because i understood the documentation like there should be recursion to the parent node, when the next node return Mstatus::kInvalidParameter for the unknown MPlug, but i cannot reach the distance plug without implementing further graph traversion.
What is the correct way to reliably find an attribute of a parent node, even when some other nodes were added in between?
The command itself should use the distance Plug to either connect to myNode or to some plug which gets the value recursively. If possible i do not want to change myOtherNode to have a distance plug and correspondig connections for forwarding the data.
The usual Maya workflow would be to make the node operate in isolation -- it should not require any knowledge of the graph structure which surrounds it, it just reacts to changes in inputs and emits new data from its outputs. The node needs to work properly if a user manually unhooks the inputs and then manually reconnects them to other objects -- you can't know, for example, that some tool won't insert a deformer upstream of your node changing the graph layout that was there when the node was first created.
You also don't want to pass data around outside the dag graph -- if the data needs to be updated you'll want to pass it as a connection. Otherwise you won't be able to reproduce the scene from the graph alone. You want to make sure that the graph can only ever produce an unambiguous result.
When you do have to do DAG manipulations -- like setting up a network of connectiosn -- put them into an MPXCommand or a mel/python script.
I found the answer in an answer (python code) to the question how to get all nodes in the graph. My code to find the node in the MPxCommand now looks like this:
MPlugArray meshConnections;
MPlug inMeshPlug = depNodeFn.findPlug("inMesh");
MItDependencyGraph depGraphIt(inMeshPlug, MFn::kInvalid, MItDependencyGraph::Direction::kUpstream);
bool offset_mesh_node_found = false;
while(!depGraphIt.isDone()) {
myNode = depGraphIt.currentItem();
if(MFnDependencyNode(myNode).typeName() == "myNode") {
offset_mesh_node_found = true;
break;
}
depGraphIt.next();
}
The MItDependencyGraph can traverse the graph in upstream or downstream direction either starting from an object or a plug. Here i just search for the first instance of myNode, as I assume there will only be one in my use case. It then connects the distance MPlug in the graph, which still works when more mesh transforms are inserted.
The MItDependencyGraph object allows to filter for node ids, but only the numeric node ids not node names. I probably add a filter later, when I have unique maya ids assigned in all plugins.

Ecommerce App in CodenameOne

Hi I am a newbie in CodenameOne am now creating a eCommerce app using CodenameOne resource editor ,I have used multilist for displaying products . I have checked the checkbox feature wherein I got the checkbox for all my items .My question here is by code in statemachine how do I get the name of product checked by the user and how to get whether the checkbox is checked or not .I tried implementing findMultiList().getSelected() but it returns always true if I check r uncheck.
Please help me also it would be great if you could tell me how to integrate google drive in my project because I need to pull data from excel sheet and populate it in the list.
You need to get the model and traverse the elements within it:
ListModel<Map<String, Object>> model = (ListModel<Map<String, Object>>)findMultiList(c).getModel();
ArrayList<Map<String, Object>> items = new ArrayList<>();
for(int iter = 0 ; iter < model.getSize() ; iter++) {
Map<String, Object> current = model.getItemAt(iter);
String checked = (String)current.get("emblem");
if(checked != null && "true".equals(checked)) {
items.add(current);
}
}
I haven't tried this code but it should work. Notice that the name "emblem" is the default name used for the MultiButton/MultiList but you can change it to be anything.
You can place a break point on the for loop and inspect the map elements as you traverse them to see how this works.
Codename One doesn't have dedicated support for google drive api yet...
However, it does support Firebase (noSQL, so no table type data)
THis means you'll have to work with variable pairs.
There are resources for table databases, though :
https://www.codenameone.com/javadoc/com/codename1/db/Database.html
check out these libraries
https://github.com/shannah/cn1-data-access-lib
(Accessing data from web, sqlite support)
https://github.com/jegesh/cn1-object-cacher
(cache from web db)
These resources should help; good luck with your development :)

java code for solr geolocation indexing

I am using solr for fixing my indexing and searching feature and a beginner to solr.
I actually want to index the geolocation into solr index and also want to make queries on it so went through some articles,
http://wiki.apache.org/solr/SpatialSearch
And exactly some schema type are present in my schema.xml.
Now my question is I want to write a java code to index the geolocation while indexing it for dynamic geolocation fields. So how to write it and is there any sample java code for indexing it. I looked for it but didn't found any so please if anybody can help me with it.
I also understand that when indexing we would need to write some thing like :
document.addField(myDynLocFld+"_p", val));
If using this approach what should be val an instance of location object with both lat and lng value embedded in it. So how to counter this or is there any diferent approach in solr java for this?
Thanking in advance.
Check this sample of code,
// Store the index in memory:
//Directory directory = new RAMDirectory();
// To store an index on disk
Directory directory = FSDirectory.open("/tmp/testindex");
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer);
IndexWriter iwriter = new IndexWriter(directory, config);
Document doc = new Document();
String text = "This is the text to be indexed.";
doc.add(new Field("fieldname", text, TextField.TYPE_STORED));
iwriter.addDocument(doc);
iwriter.close();
For more details check Lucene APIs.

Indexing PDF documents with addtional search fields using SolrNet?

I found this article useful when indexing documents, however, how can I attach additional fields so I can pass in, say, the ID of the document in our database for use in displaying the search results? I thought by using the Fields (Of the ExtractParameters class) property I could index additional data with the document, but that doesn't seem to work or that is not its function.
Example code:
var solr = ObjectLocator.Instance.Resolve<ISolrOperations<IndexDocument>>();
var guid = Guid.NewGuid().ToString();
using (var fileStream = System.IO.File.OpenRead(Server.MapPath("~/files/") + "greenroof.pdf"))
{
var response =
solr.Extract(
new ExtractParameters(fileStream, "greenRoof1234")
{
ExtractFormat = ExtractFormat.Text,
ExtractOnly = false,
Fields = new[] { new ExtractField("field1", "value1"), new ExtractField("field2", "value2") }
});
}
#aitchnyu is correct, passing the values via the literal.field=value method is the correct way to do this.
However, according to this post on ExtractingRequestHandler support in the SolrNet Google Group, there was a bug with the ExtractParameters.Fields not working properly. This was fixed in the 0.4.0.X versions of SolrNet. Please make sure you are using one of the latest versions of SolrNet. You can obtain that by one of the following means:
Project Site Downloads
NuGet PreRelease Package
Also that discussion has some good examples of using the ExtractingRequestHandler in SolrNet as well as a workaround for adding the additional field values if you cannot upgrade to a newer version of SolrNet.
This is sufficient: http://wiki.apache.org/solr/ExtractingRequestHandler#Literals .
In general use a literal.field=value while uploading.
It turned out not to be an issue with SOLRNet, but my knowledge of SOLR, in general. I needed to specify the fields in my schema. After i added the fields to my schema they were visible in my SOLR query.

Resources