I've been working on Neo4j recently and i know basic rules and how to select property names. However , i need to get the identifier name.
Here is the code:
CREATE (Jugan:Person {name:'George'})
I DON'T want to find 'George' name, but i wanna get the identifier name that is 'Jugan'.
When i write something with " match and return " stuff , i wanna get this "Jugan" name. I hope i explained clearly.
Identifiers are not persisted at all. Their lifetime is just the current statement and their main usage is to refer back to a known node e.g. for returning them.
So no luck finding Jugan in your example. Introduce a property for this.
This is called a label. When you return you can use the LABELS() function like so:
RETURN labels(node)
Since nodes can have zero or more labels, this will give you an array.
Related
So i've got a bot that serves as a roleplaying mamager handeling combat, skill points and the like, i'm trying to make my code a bit more general so i can have less pages since they all do the same thing they just have different initilizers but i ran into a snag i need to check if the user has a minimum in a particular stat Strength, perceptions, agility, etc
so i call
mainSPECIAL = rows[0].Strength;
Here's the rub, weathers it strength, percpetion, intelligence, luck, whatever i'm always going to be checking Rows[0].that attribute ie Rows[0].Luck for luck perks, and i already set earlier in my initilizers
var PERKSPECIALName = "Strength";
But i can't call
mainSPECIAL = rows[0].PERKSPECIALName but there should be a way to do that right? so that when it sees "rows[0].PERKSPECIALName" it looks up "PERKSPECIALName" and then fetches the value of rows[0].Strength
For this you need to use reflection:
Field f1 = rows[0].getClass().getField(PERKSPECIALName);
Integer attribute = (Integer) f1.get(rows[0]);
Where "Integer" is the type of the element your pulling from the object (the type of strength)
The field must be declared as public! I think there is a way to obtain them when they are not public but it requires more code.
Seems like you have a set of integers that you need to identify with a constant identifier. You might find an EnumMap useful. Have a look at How to use enumMap in java.
Or if you want to only use a string to identify which perk you want to reference, just use a Map.
Java doesn't have reference-to-member like some other languages, so if you don't want to change your data structure, you are looking at using lambda functions or heavier language features to increase re-use, which seems like overkill for what you're trying to do.
I need to be able to set the initial value of an enumeration literal using the EA Java Automation API. Unfortunately I failed in finding out how this can be achieved in the manual. As I found out an Enumeration is actually represented by an Element in the EA object model. I am creating an element elem of type Enumeration and I am adding an Attribute to it by using the following code:
org.sparx.Attribute attr1 = elem.GetAttributes().AddNew("PTS_OFF", "Enum");
Then I am able to change certain properties of this attribute but I cannot find a setter for the initial value which is available in the GUI.
Is there a dedicated API for this or I can do that with the GUI only (by right-clicking on Enumeration entry->Properties->Details->Attributes->General->Initial Value)? I am using EA v11.
Problem solved! I suspected it was easier than it looked. Thanks to Thomas Kilian who gave the idea of using the SQL for this task, I was able to perform a search and find out which field in the database exactly corresponds to the "Initial value" in the dialog. It turns out that the following code updates the initial value: attr1.SetDefault("my initial value");
Using SQL also works but it is the more complex way to go in this case as the attribute element actually contains a setter for this. Following Thomas's proposal, one can do the following:
Repository.Execute("UPDATE t_attribute SET Default='my init value' where Name = 'PTS_OFF'");
I've got loads of the following to implement.
validateParameter(field_name, field_type, field_validationMessage, visibleBoolean);
Instead of having 50-60 of these in a row, is there some form of nested hashmap/4d array I can use to build it up and loop through them?
Whats the best approach for doing something like that?
Thanks!
EDIT: Was 4 items.
What you could do is create a new Class that holds three values. (The type, the boolean, and name, or the fourth value (you didn't list it)). Then, when creating the HashMap, all you have to do is call the method to get your three values. It may seem like more work, but all you would have to do is create a simple loop to go through all of the values you need. Since I don't know exactly what it is that you're trying to do, all I can do is provide an example of what I'm trying to do. Hope it applies to your problem.
Anyways, creating the Class to hold the three(or four) values you need.
For example,
Class Fields{
String field_name;
Integer field_type;
Boolean validationMessageVisible;
Fields(String name, Integer type, Boolean mv) {
// this.field_name = name;
this.field_type = type;
this.validationMessageVisible = mv;
}
Then put them in a HashMap somewhat like this:
HashMap map = new HashMap<String, Triple>();
map.put(LOCAL STRING FOR NAME OF FIELD, new Field(new Integer(YOUR INTEGER),new Boolean(YOUR BOOLEAN)));
NOTE: This is only going to work as long as these three or four values can all be stored together. For example if you need all of the values to be stored separately for whatever reason it may be, then this won't work. Only if they can be grouped together without it affecting the function of the program, that this will work.
This was a quick brainstorm. Not sure if it will work, but think along these lines and I believe it should work out for you.
You may have to make a few edits, but this should get you in the right direction
P.S. Sorry for it being so wordy, just tried to get as many details out as possible.
The other answer is close but you don't need a key in this case.
Just define a class to contain your three fields. Create a List or array of that class. Loop over the list or array calling the method for each combination.
The approach I'd use is to create a POJO (or some POJOs) to store the values as attributes and validate attribute by attribute.
Since many times you're going to have the same validation per attribute type (e.g. dates and numbers can be validated by range, strings can be validated to ensure they´re not null or empty, etc), you could just iterate on these attributes using reflection (or even better, using annotations).
If you need to validate on the POJO level, you can still reuse these attribute-level validators via composition, while you add more specific validations are you´re going up in the abstraction level (going up means basic attributes -> pojos -> pojos that contain other pojos -> etc).
Passing several basic types as parameters of the same method is not good because the parameters themselves don't tell much and you can easily exchange two parameters of the same type by accident in the method call.
Just a quick one. If I'm using an EJBQL query with named parameters, can I use the same parameter name twice in a single query to avoid having to set the value twice when I actually want to run the query? For instance, I'd like to be able to do something like this:
SELECT g FROM Group g WHERE g = :group OR g.parent = :group
...so that doing:
query.setParameter("group", theGroup);
will populate both fields. Is this possible?
I realize I could just run this and see, but I figured that asking first might save me (and anyone else who happens to find this question) a bit of time and frustration.
Yes, it's part of the spec. Makes no sense for a spec to insist on passing in an extra param name with dup value
How a particular fact inserted in the knowledge through a java code and its corresponding fact in a DRL file are mapped or bound to each other, Because as in my application I can insert multiple facts of the same type, wanted to know how a particular rule(condition) will pick a particular fact for its execution.
need some info or sample examples.
thanks.
A rule that matches an Object type for example Person(), will be activated for all the Person instances that you insert inside your session. Adding constrains inside the Object type like for example: Person(name == "John") only the instance with name John will activate that rule.
Cheers