micropython for statement syntax - micropython

Recently came upon the following syntax that includes elements for which I have been unable to find a reference:
for(auto i = 0u; i < (reference to an object element here) ; i++)
To what does "auto" refer? What is the "u" modifying the initial index?
Alternatively, where can I find documentation relating to these questions. Thanks.

Related

How to access list element in FEEL list literal expression in DMN?

I have the following list of the object:
"animals":[
{
"family":"cat",
"color":"grey"
},
{
"family":"dog",
"color":"white"
}
]
I want to access first animal object that is in dog family and white color. I am trying to achieve it by doing this:
animals[family = "dog" and color = "white"][0]
But it shows warning as follows:
FEEL WARN while evaluating literal expression 'animals[ family = .... [string clipped after 50 chars, total length is 82]': Index out of bound: list of 1 elements, index 0; will evaluate as FEEL null
What exactly is incorrect here? I feel I am doing wrong something semantically. I also referred FEEL's specification but am unable to figure out what's wrong. I also referred dmn decision modeling documentation for DMN from Redhat but still I am clueless. Please help.
In FEEL, the list's elements index starts at 1.
So the expression you want to access first animal object, actually is:
animals[family = "dog" and color = "white"][1]
This is documented in the DMN specification at page 126:
The first element of a list L can be accessed using L[1] and the last
element can be accessed using L[-1].
To provide a more friendly reference, this is also documented in Drools documentation
Elements in a list can be accessed by index, where the first element
is 1. Negative indexes can access elements starting from the end of
the list so that -1 is the last element.
...and equivalently for the productized Red Hat documentation version as well:

How to generate code from custom scoping through instances?

I'm trying to write a code generator using xtext. There are instances of types declared in the corresponding DSL, attributes can be referenced through those instances by custom scoping (see code for example). The linking is performed directly from referencing element to attribute, so that there is no information about the surrounding instance - but for code generation, I exactly need the qualified name that is added in the DSL file. Is there any other possibility so that I can figure out through which instance the actual feature is referenced?
My first idea was to recall the ScopeProvider at code generation, which works but does not react on two instances of same type because the first matching Attribute is chosen - so if there are multiple instances, the generator cannot distinguish which one is meant.
Second idea was to include information from the corresponding DSL file, but I don't have any idea how to get this work. I already searched a lot if it is possible to get the corresponding DSL-file from the current model, but could not find any helpful answer.
Third idea was to include the instance as a hidden field in the referencing element - but I could not find any solution for this approach too.
Small extract of Grammar (simplified):
Screen:
(features += ScreenFeature)*
;
ScreenFeature:
name=ID ':' type=[ClientEntity]
;
ClientEntity:
(features += Feature)*
;
Feature:
name=ID ':' type=DefaultValue
;
DefaultValue:
'String'|'int'|'double'|'boolean'
;
ChangeViewParam:
param=[ScreenFeature|QualifiedName] ':' value=[ScreenFeature|QualifiedName]
;
DSL-Example:
ClientEntity Car {
id : int
name : String
}
Screen Details {
car : Car
car2 : Car
[...]
car2.id : car.id
}
Generation output of first approach (line: car2.id : car.id) :
car.id : car.id
Expected:
car2.id : car.id
I hope you can understand my problem and have an idea how to solve it. Thanks for your help!
You can use
org.eclipse.xtext.nodemodel.util.NodeModelUtils.findNodesForFeature(EObject, EStructuralFeature) to obtain the nodes for YourDslPackage.Literals.CHANGE_VIEW_PARAM__PARAM (should be only one) and ask that one for its text.
Alternatively you could split your param=[ScreenFeature|QualifiedName] into two references

JanusGraph indexing in Scala

I am using Spark to make a JanusGraph from a data stream, but am having issues indexing and creating properties. I want to create an index by a vertex property called "register_id". I am not sure I'm doing it the right way.
So, here's my code:
var gr1 = JanusGraphFactory.open("/Downloads/janusgraph-cassandra.properties")
gr1.close()
// This is done to clear the graph made in every run.
JanusGraphFactory.drop(gr1)
gr1 = JanusGraphFactory.open("/Downloads/janusgraph-cassandra.properties")
var reg_id_prop = gr1.makePropertyKey("register_id").dataType(classOf[String]).make()
var mgmt = gr1.openManagement()
gr1.tx().rollback()
mgmt.buildIndex("byRegId", classOf[Vertex]).addKey(reg_id_prop).buildCompositeIndex()
When I run the above, I get an error saying:
"Vertex with id 5164 was removed".
Also, how do I check if I have vertices with a certain property in the graph or not in Scala. I know in gremlin, g.V().has('name', 'property_value') works, but can't figure out how to do this in Scala. I tried Gremlin-Scala but can't seem to find it.
Any help will be appreciated.
You should be using mgmt object to build the schema, not the graph object. You also need to make sure to mgmt.commit() the schema updates.
gr1 = JanusGraphFactory.open("/Downloads/janusgraph-cassandra.properties")
var mgmt = gr1.openManagement()
var reg_id_prop = mgmt.makePropertyKey("register_id").dataType(classOf[String]).make()
mgmt.buildIndex("byRegId", classOf[Vertex]).addKey(reg_id_prop).buildCompositeIndex()
mgmt.commit()
Refer to the indexing docs from JanusGraph.
For your second question on checking for the existence of a vertex using the composite index, you need to finish your traversal with a terminal step. For example, in Java, this would return a boolean value:
g.V().has('name', 'property_value').hasNext()
Refer to iterating the traversal docs from JanusGraph.
Reading over the gremlin-scala README, it looks like it has a few options for terminal steps that you could use like head, headOption, toList, or toSet.
g.V().has('name', 'property_value').headOption
You should also check out the gremlin-scala-examples and the gremlin-scala traversal specification.

Sentence similarity - How to calculate the depth of subsumer using WordNet?

I try to build a tool to calculate the similarity between 2 words and I found that there is a formula come from Manchester Metropolitan University as following:
Until now, I am still confused how to get the h which is the depth of subsumer in the hierarchical semantic nets.
As my understanding, h is the path length from the top word to the a certain word, as reference from the author, the top word is 'entity' for NOUN.
But how about another kind of word such as ADJ, ADV, VERB...?
And if we already have the top word, how can we list out the path from it to the word we need to calculate
The paper is at the following link: https://www.researchgate.net/profile/Keeley_Crockett/publication/232645326_Sentence_Similarity_Based_on_Semantic_Nets_and_Corpus_Statistics/links/0deec51b8db68f19fa000000.pdf
Really appreciate for any answer.
Thanks
Every time I've tried to understand the Wordnet hierarchy I found something that invalidates everything I previously assumed :)
Regarding similarities, if you are using Python and NLTK, I'd recommend you use the provided similarity metrics, if not, those may be a good start to understand how things work.
In this link, scroll down to Similarity:
http://www.nltk.org/howto/wordnet.html
I would like to add more detail which I have just found.
These details are enough for my searching but may not exactly with the question above, but I think I need to share to somebody need it in future.
'Entity' is not only root of Noun, but also the root of any word even it is VERB, ADJ, ADV....
Ex full path for the word 'kiss': ROOT#n#1 < entity#n#1 < abstraction#n#6 < psychological_feature#n#1 < event#n#1 < act#n#2 < touch#n#5 < kiss#n#1
EX full path for the word 'kick': ROOT#n#1 < entity#n#1 < abstraction#n#6 < psychological_feature#n#1 < event#n#1 < act#n#2 < speech_act#n#1 < objection#n#2 < kick#n#4
To calculate the depth of any word, we need to calculate from the beginning word ('entity') and base on the Word Net hierarchical database.
Come back to above example, the h (length of subsummer of 'kiss' and 'kick') is 6, which is count from the top tree node root to the word 'act'

Finding magic numbers using NDepend

Does anyone know how I could find magic numbers in the source code using the CQL queries in NDepend? This is the same problem as this question, but I don't want to use regex if possible.
So I want to find all statements like
Int32 someValue = 23;
Double anotherValue = 1;
but not
for (int i = 0; i < array.length; i++)
I confirm, currently NDepend and CQLinq cannot help with that.
I would advise you do a small app using Mono.Cecil, and search for magic numbers and strings.
You'll see, Mono.Cecil API rocks!
It's a nice idea but I'm pretty certain you can't do it as there is no way to query inititialisation values in CQL.