DXL scrippting for find the enum in attributs - ibm-doors

How I can find a string in Doors attributes . e.g.
I have doors attributes, which has values type of Enumeration
1. AA 2. BB 3. cc 4. dd
How I can find DXL script that in particular attributes , say it contains two AA, and 3 BB

I do not understand what you mean with "two AA", in a multi value enumeration, an attribute either has AA set or not set, it cannot be set twice.
If you have a multi value enumeration with the allowed values "AA", "BB", "cc" and "dd", you can use the perm bool isMember(attrRef, string).
Example from DXL manual:
if (isMember((current Object)."Country", "Australia")) {
addRequirement("Right-hand drive model needed")
}

Related

How do i remove rows based on comma-separated list of values in a Power BI parameter in Power Query?

I have a list of data with a title column (among many other columns) and I have a Power BI parameter that has, for example, a value of "a,b,c". What I want to do is loop through the parameter's values and remove any rows that begin with those characters.
For example:
Title
a
b
c
d
Should become
Title
d
This comma separated list could have one value or it could have twenty. I know that I can turn the parameter into a list by using
parameterList = Text.Split(<parameter-name>,",")
but then I am unsure how to continue to use that to filter on. For one value I would just use
#"Filtered Rows" = Table.SelectRows(#"Table", each Text.StartsWith([key], <value-to-filter-on>))
but that only allows one value.
EDIT: I may have worded my original question poorly. The comma separated values in the parameterList can be any number of characters (e.g.: a,abcd,foo,bar) and I want to see if the value in [key] starts with that string of characters.
Try using List.Contains to check whether the starting character is in the parameter list.
each List.Contains(parameterList, Text.Start([key], 1)
Edit: Since you've changed the requirement, try this:
Table.SelectRows(
#"Table",
(C) => not List.AnyTrue(
List.Transform(
parameterList,
each Text.StartsWith(C[key], _)
)
)
)
For each row, this transforms the parameterList into a list of true/false values by checking if the current key starts with each text string in the list. If any are true, then List.AnyTrue returns true and we choose not to select that row.
Since you want to filter out all the values from the parameter, you can use something like:
= Table.SelectRows(#"Changed Type", each List.Contains(Parameter1,Text.Start([Title],1))=false)
Another way to do this would be to create a custom column in the table, which has the first character of title:
= Table.AddColumn(#"Changed Type", "FirstChar", each Text.Start([Title],1))
and then use this field in the filter step:
= Table.SelectRows(#"Added Custom", each List.Contains(Parameter1,[FirstChar])=false)
I tested this with a small sample set and it seems to be running fine. You can test both and see if it helps with the performance. If you are still facing performance issues, it would probably be easier if you can share the pbix file.
This seems to work fairly well:
= List.Select(Source[Title], each Text.Contains(Parameter1,Text.Start(_,1))=false)
Replace Source with the name of your table and Parameter1 with the name of your Parameter.

Reordering text in DOORS layout column using DXL

I have seen this question asked for numbers, but my layout column consists of strings of text. There is no inherent order to the strings and the possible values for the attribute connected to an object could be, for example "apple", "orange", "banana", or "kiwi". The column I want looks for in-links from another module and each in-link can have multiple values for the attribute in question. Ultimately I want the values to be ordered "orange", "banana", "kiwi", "apple" depending on what values each linked objects have. For example, if the linked object contains all 4 then you would get the list of the full order. If it only has banana and apple you would return the value for the column "banana" , "kiwi". Sorry I don't have a code sample. At this point it would just be the stock layout column DXL though. Thanks for any help.
If your real world is really as simple as your example, it might be sufficient to just have a combination of if statement s, like (pseudocode)
if linked_values contains "orange"
display "orange\n"
if linked_values contains "banana"
display "banana\n"
and you have a nice, sorted list of values.
If not, you need real sorting.
Sorting in DXL is usually done using skip lists. When you iterate over a skip list, you get the values in the order of the sorted keys (note that keys are unique, there cannot be two objects with the same key in a skip list).
So, it would be your task to create a mapping that for each entry to be stored calculates a key that represents the correct order and a temporary skip list.
If I understand your example correctly, you would have a mapping
orange: a
banana: b
kiwi: c
apple: d
Let's assume that there may be multiple oranges per object and you want to list all of them, because you do not only want to display the fruit but also some attribute like size or quality. In this case, you would create sort keys like this:
Object 1 has linked objects with the values: first apple (big), second apple (small), kiwi (medium), third apple (big), orange. This would make the following skip list:
key: d001, value: apple (big)
key: d002, value: apple (small)
key: c003, value: kiwi (medium)
key: d004, value: apple (big)
key: a005, value: orange
If you want to sort first by fruit, then by size, and you code your sizes by a: big, b: medium, c: small, d: undefined, you would have keys like:
da001
dc002
cb003
da004
ad005

Data structures in Rascal

I am looking for a data structure that can mimic an Object or a struct. Really, just some compact way to pass around different types of variables. Currently I am using a tuple but referencing various parts of the tuple is less pleasant than I would like. Currently I've just created aliases that represent the various locations in the tuple:
alias AuxClass = tuple[str,str,list[int],list[int],Dec];
int ACLS = 0;
But I've had to restructure this tuple and thus had to change the indexing. Is there something I can use here that I've missed or perhaps a feature coming in the future?
Thanks!
Please take a look at the algebraic data types feature:
http://tutor.rascal-mpl.org/Rascal/Rascal.html#/Rascal/Declarations/AlgebraicDataType/AlgebraicDataType.html
You can create a constructor to represent the type of data that you are trying to define above, similar to what you would do with a struct, and give each element in the constructor a field name:
data AuxClass = auxClass(str f1, str f2, list[int] f3, list[int] f4, Dec f5)
You can then create new instances of this just using the constructor name and providing the data:
a = auxClass("Hello", "World", [1,2,3], [4,5,6], D1) (where D1 is a Dec).
Once you have an instance, you can access information using the field names:
a.f1 // which equals "Hello"
a.f3 // which equals [1,2,3]
size(a.f3) // which currently equals 3
and you can update information using the field names:
a.f2 = "Rascal"
a.f4 = a.f4 + 7 // f4 is now [4,5,6,7]
Algebraic data types are actually quite flexible, so there is a lot you can do with them beyond this. Feel free to look through the documentation and ask questions here.

Accessing values from hashamp without specifying key in redis

I would like to access value with the given pattern from hash in redis with out providing key.
Example
HSET myKey va11 "Hello" val2 "Hi" Val3 "GooMorning" val4 "Good Evening"
HSET myKey2 va11 "one val2 "two" Val3 "three" val4 "four"
I have set of keys with their values as above. Is there any way to retrieve values without providing keys.
i just want to check is there any value with Good* something like that without providing key.
I saw that you're using the "lua" tag - if LUA is not a a must, please consider the following example using HVALS. I'l provide some redis-py code to go with:
import redis
# connect to local redis-server:6379
r = redis.Redis()
# initialize sample "myKey" hash
r.hmset("myKey", {'val1': "Hello", 'val2': "Hi", 'val3': "GoodMorning", 'val4': "Good Evening"})
# provide "starts with" pattern (this could obviously be a regex as well)
pattern = "Good"
# find all values starting with the pattern and return them
values_matching = filter(lambda x: x.startswith(pattern), r.hvals("myKey"))
# print values: ["GoodMorning", "Good Evening"]
print values_matching
You don't say that you need the keys for the matching values. If you do, then you should look into the HGETALL command.
EDIT after reading your comments: yes, you will need to loop over all key/values in the hash using HGETALL. An amended example following:
import redis
r = redis.Redis()
r.hmset("myKey", {'val1': "Hello", 'val2': "Hi", 'val3': "GoodMorning", 'val4': "Good Evening"})
pattern = "Good"
# use hgetall() to iterate over all key-value pairs and form values_matching by looking only at pairs where the value starts with "Good"
values_matching = dict([(k, v) for k, v in r.hgetall("myKey").iteritems() if v.startswith(pattern)])
# print values: {'val3': 'GoodMorning', 'val4': 'Good Evening'}
print values_matching
Redis doesn't provide this functionality out of the box. However, if I understand your question correctly, you can easily add it.
Keep a sorted set, for example call it allvals, with all the values from your hashes (i.e. do a ZADD to it on every hash update). Use ZRANGEBYLEX on it for suffix searching as means for existence checking:
ZRANGEBYLEX allvals "[Good" "[Good\xff"
EDIT: Given your clarification, this approach is not what you're looking for. Here's my take on the revised challenge.
So. What you're looking for is a way to fetch hash key names if they contain a specific value in one of their fields. One way would be to scan all you hashes and look for that value (as #tobiash suggested) but, depending on the size of your dataset, this may be quite expensive. Another way to go about this is to use sets as means for indexing your hashes. The basic premise is to take every value in the hash(es) and create sets for it. Each such set's members would be the actual key names of the hashes that contain that value.
Let's see how your example's myKey should be indexed (yes, we're building an index here). To begin with, you'll create the following sets out of it:
SADD idx:Hello myKey
SADD idx:Hi myKey
SADD idx:GooMorning myKey
SADD "idx:Good Evening" myKey
Now, by doing SMEMBERS on idx:Hello, you'll get all the key names that have Hello as values. However, since what you're looking for is doing suffix searching, for each value you'll actually need to maintain multiple sets, where each set indexes a substring of the value. For example, for the string Hello you'll actually need:
SADD idx:H myKey
SADD idx:He myKey
SADD idx:Hel myKey
SADD idx:Hell myKey
SADD idx:Hello myKey
Lua can help here if you'll create a script that you'll call to update your hashes. The script should be given the hash key name and the field names + values. Once called, the script will need not only to create/update the actual hash, but also to iterate over all field values and construct the index for them (and their respective substrings).
Let us know if you need help with writing that script ;)

Using labels in Batch import

In the new 2.0 branch of the NEO4J batch-importer,
To specify a label, I believe one must specify the header,
Using the example from the readme.md and wiki:
name l:label age works_on
Michael Person,Father 37 neo4j
Selina Person,Child 14
Rana Person,Child 6
Selma Person,Child 4
Does the header always have to follow the following format of being l:label and
What does the comma do and is it optional?
ie. What does person,Father represent? label,???
I believe in this case Person is the label but I'm curious how can I query (in cypher) the label value in this case either Father or Child.
I think if you wanted to explicitly assign the type of some property you would use colon + type for that, i.e.
name:String age:int
and :label is used after the fashion of a data type to signal that the value(s) in a field is a node label or a relationship type. Since labels are not name/value pairs like properties, I would think the l in l:label doesn't really do anything.

Resources