I'm currently trying to read a sparksee object by it's Type and by multiple attributes. I found out I can do select:
and that there is a select method which has an "Objects" value. But I wasn't able to find out what it is for. Is there a way to do something like.
or do I have to check one of the properties and then run through all of them manually? |
/**
* Returns a Value object for a certain object.
* @param obj ingoing object.
* @return outgoing value.
*/
protected static Value getValue(Object obj)
{
Value v = new Value();
switch(getDataTypeFromObject(obj))
{
case Boolean:
return v.setBoolean((Boolean) obj);
case Integer:
return v.setInteger((java.lang.Integer) obj);
case Long:
return v.setLong((java.lang.Long) obj);
case Double:
return v.setDouble((java.lang.Double) obj);
default:
return v.setString((java.lang.String) obj);
}
}
/**
* Gets a dataType from a certain object.
* @param obj the ingoing object.
* @return outgoing dataType, default a string.
*/
protected static DataType getDataTypeFromObject(Object obj)
{
if(obj instanceof Integer)
{
return Integer;
}
else if(obj instanceof Long)
{
return Long;
}
else if(obj instanceof Boolean)
{
return Boolean;
}
else if (obj instanceof Double)
{
return Double;
}
return String;
} Additionally, isn't there a way to execute createOrFindNodeType or createOrFindAttribute? This way I don't have to execute all the:int nodeTypeId = graph.findType(storage.getId());
if (Type.InvalidType == nodeTypeId)
{
return graph.newNodeType(storage.getId());
}
return nodeTypeId; and just could: createOrFindNodeType(type)
The select operations that receive an Objects argument (like this) can be used to select only the objects from the given set that satisfy the condition. You can get the same result with an intersection between the argument Objects and the normal Select result Objects, but using the specific method may be more efficient.
Sparksee does not have a Select that receives an array of values.
Depending on the values you may be able to use a different
Condition to achieve the same result (with Between, Like, RexExp,
...) otherwise you will have to do all the selects and union the
resulting Objects.
Hi,
Yes, you can do something like:
obj1 = graph.select(nameAttr, Condition.Equal, value.setString("paul"));
obj2 = graph.select(ageAttr, Condition.Equal, value.setInteger(23));
obj3 = graph.select(heightAttr, Condition.Equal, value.setInteger(2));
obj4 = Objects.combineIntersection(obj1, obj2);
obj4.intersection(obj3);
Or you could use the Select operation restricted to the given objects:
obj1 = graph.select(nameAttr, Condition.Equal, value.setString("paul"));
obj2 = graph.select(ageAttr, Condition.Equal, value.setInteger(23), obj1);
obj3 = graph.select(heightAttr, Condition.Equal, value.setInteger(2), obj2);
Best regards
Hi,
You may want to look at the Sparksee Starting Guide.
The section 6 will give you a simple example of how to iterate the Objects to get the node ids and get an attribute from a specific node, while the section 5 will show you how to create an edge between two nodes and the section 4 will be useful to understand the schema of the example.
Best regards
Hi,
There are four types of attributes in Sparksee: specific to type, specific to node, specific to edge and global. In the first case, the attribute will be created for a specific node or edge type, thus when you perform a select for that attribute it will only return nodes or edges of that certain type and you must then search for the specific attribute id of each type and perform a union of all the objects obtained.
For the second and third cases, the attribute created can be used on any
node or any edge and it's not tied to a specific type, this will
be indicated by using "Type.NodesType" or "Type.EdgesType"
depending if you want to create an attribute for all your nodes or
an attribute for all your edges. Finally, for the global
attributes, they can be used for any node and edge, thus not tied
to neither edge/node nor the type.
Please read more information about the attributes here.
Hi,
The kind of objects returned in a Select depend on the type of
attribute used:
If you use a specific to type attribute, it will only return objects of that type (wich can be a specific Node Type or a specific Edge Type) so you already know in advance if the result will be a set of nodes or edges.
If you use a NodesType attribute, the result will be a set of
nodes, but they may belong to different node types.
If you use an EdgesType attribute, the result will be a set of edges, but they may belong to different edge types.
If the attribute is Global, the result will be a set that can contain both nodes and edges of any type.
Nevertheless, you can always use the "Graph.getObjectType"
method to find the type from an object identifier, the "Graph.getType"
method to find information about the type and the "Type.getObjectType"
to find out if it's an "ObjectType.Node"
or an "ObjectType.Edge".
Session sess = db.newSession();
Hi,
The free download version only allows one single session at a time, so you should close the previous one before trying to open a new one. If you are going to need concurrent sessions, please go ahead and request a license through our website, choosing the one that best fits your situation (Researcho or Development) filling in the form.
Best Regards
HI,
The Sparksee settings will be automatically loaded if a file with the name "sparksee.cfg" is present in the working directory or you can load any file using the "SparkseeProperties.load" method before creating the SparkseeConfig object. More details can be found here.
Best regards