In my network, the relevant part of the model is as below.
asset Farm identified by farmId{
o String farmId
o String FarmLocation
o String[] images optional
o String[] waterSources
o String[] nearFactories
o String otherDescription optional
o Certification certification
--> Stakeholder owner
o String[] farmers
}
participant Stakeholder identified by stakeholderId{
o String stakeholderId
o String name
o Address address
o String email optional
o String telephone optional
o Certification certification optional
o String[] images optional
o Company company
o String username
o String password
o StakeholderType type
o String description optional
o String authPerson
o String vehicleNo optional
o DistType distributionType optional
o String branchNo optional
}
In Farm asset, I store relevant Farmer participants' identifiers as a string array under farmers attribute. I want to allow only the farmers whose IDs include in this array, to access the Farm asset. To achieve that I tried below access rule. But It does not seem working as expected.
rule FarmersHasAccessToTheirFarms {
description: "Allow all participants full access to their assets"
participant(p): "org.ucsc.agriblockchain.Stakeholder"
operation: ALL
resource(r): "org.ucsc.agriblockchain.Farm"
condition: (p.type == "FARMER" && p.stakeholderId in r.farmers)
action: ALLOW
}
How to achieve this requirement? Any suggestions?
you can use the .some function - someone has already posted an answer here -> Includes function in ACL condition that is similar to what you want to achieve.
eg something like
condition: (p.type == "FARMER" && (r.farmers.some(function (checkstake) {
return checkstake === p.stakeholderId;
} ))
Related
Hi i am trying to tag the words in a sentence in order.
For example, (my initial method)
Sentence: Work across a wide range of related areas
Label: Tag O O O O O Tag Tag
But now i need it to be like this where it can tag 2 words as a keyword aand label it together:
Sentence: Work across a wide range of related areas
Label: Tag O O O O O Tag
I have a list of keyword of varying length and their tags. How can i tag the way i need it to be in the sentence order?
Looks like what you are looking for is the BIO-tagging system (If I understood you correctly, and you are looking for a solution in manually tagged corpora).
BIO denotes the following: B - beginning of a chunk, I - the inside of the chunk, O - is a token outside of a chunk.
Step 1
Sentence: Work across a wide range of related areas
Tag: B O O O O O B I
Label: Label_1 O O O O O Label_2 Label_2
Step 2
Sentence: Work across a wide range of related areas
Label: B-Label_1 O O O O O B-Label_2 I-Label_2
Once you have tagged your corpus, you will align the lists of Sentences (list #1) and Tag + Label combos (list #2):
the BIO tags will be prefixed to your labels, e.g., [...related, areas] + [... B-Label_2, I-Label_2].
That way you can combine [B-Label_2, I-Label_2] into one Label_2 since you have a pattern of BI together. You will just have to strip the prefixes at the very end and do a lot of other intermediate steps and post-processing.
The string is like this:
TEMPLATES="!$TEMPLATE templatename manufacturer model mode\n$TEMPLATE MacQuantum Wash Basic\n$$MANUFACTURER Martin\n$$MODELNAME Mac Quantum Wash\n$$MODENAME Basic\n"
My way to get strings without tags is:
local sentence=""
for word in string.gmatch(line,"%S+") do
if word ~= tag then
sentence=sentence .. word.." "
end
end
table.insert(tagValues, sentence)
E(tag .." --> "..sentence)
And I get output:
$$MANUFACTURER --> Martin
$$MODELNAME --> Mac Quantum Wash
...
...
But this is not the way I like.
I would like to find first the block starting with $TEMPLATE tag to check if this is the right block. There is many such blocks in a file I read line by line. Then I have to get all tags marked with double $: $$MODELNAME etc.
I have tried it on many ways, but none satisfied me. Perhaps someone has an idea how to solve it?
We are going to use Lua patterns (like regex, but different) inside a function string.gmatch, which creates a loop.
Explanation:
for match in string.gmatch(string, pattern) do print(match) end is an iterative function that will iterate over every instance of pattern in string. The pattern I will use is %$+%w+%s[^\n]+
%$+ - At least 1 literal $ ($ is a special character so it needs the % to escape), + means 1 or more. You could match for just one ("%$") if you only need the data of the tag but we want information on how many $ there are so we'll leave that in.
%w+ - match any alphanumeric character, as many as appear in a row.
%s - match a single space character
[^\n]+ - match anything that isn't '\n' (^ means invert), as many as appear in a row.
Once the function hits a \n, it executes the loop on the match and repeats the process.
That leaves us with strings like "$TEMPLATE templatename manufacturer"
We want to extract the $TEMPLATE to its own variable to verify it, so we use string.match(string, pattern) to just return the value found by the pattern in string.
OK: EDIT: Here's a comprehensive example that should provide everything you're looking for.
templates = "!$TEMPLATE templatename manufacturer model mode\n$TEMPLATE MacQuantum Wash Basic\n$$MANUFACTURER Martin\n$$MODELNAME Mac Quantum Wash\n$$MODENAME Basic\n"
local data = {}
for match in string.gmatch(templates, "%$+%w+%s[^\n]+") do --finds the pattern given in the variable 'templates'
--this function assigns certain data to tags inside table t, which goes inside data.
local t = {}
t.tag = string.match(match, '%w+') --the tag (stuff that comes between a $ and a space)
t.info = string.gsub(match, '%$+%w+%s', "") --value of the tag (stuff that comes after the `$TEMPLATE `. Explanation: %$+ one or more dollar signs $w+ one or more alphanumeric characters $s a space. Replace with "" (erase it)
_, t.ds = string.gsub(match, '%$', "") --This function emits two values, the first one is garbage and we don't need (hence a blank variable, _). The second is the number of $s in the string).
table.insert(data, t)
end
for _,tag in pairs(data) do --iterate over every table of data in data.
for key, value in pairs(tag) do
print("Key:", key, "Value:", value) --this will show you data examples (see output)
end
print("-------------")
end
print('--just print the stuff with two dollar signs')
for key, data in pairs(data) do
if data.ds == 2 then --'data' becomes a subtable in table 'data', we evaluate how many dollar signs it recognized.
print(data.tag)
end
end
print("--just print the MODELNAME tag's value")
for key, data in pairs(data) do
if data.tag == "MODELNAME" then --evaluate the tag name.
print(data.info)
end
end
Output:
Key: info Value: templatename manufacturer model mode
Key: ds Value: 1
Key: tag Value: TEMPLATE
-------------
Key: info Value: MacQuantum Wash Basic
Key: ds Value: 1
Key: tag Value: TEMPLATE
-------------
Key: info Value: Martin
Key: ds Value: 2
Key: tag Value: MANUFACTURER
-------------
Key: info Value: Mac Quantum Wash
Key: ds Value: 2
Key: tag Value: MODELNAME
-------------
Key: info Value: Basic
Key: ds Value: 2
Key: tag Value: MODENAME
-------------
--just print the stuff with two dollar signs
MANUFACTURER
MODELNAME
MODENAME
--just print the MODELNAME tag's value:
Mac Quantum Wash
Through an online Dart course, I've found some values bracketed with "less than" and "greater than" marks such as "List< E >".
e.g.
List<int> fixedLengthList = new List(5);
I couldn't find a direct answer online, probably because that question was too basic. Could someone explain what those marks exactly indicate? Or any links if possible.
This are generic type parameters. It allows specializations of classes.
List is a list that can contain any value (if no type parameter is passed dynamic is used by default).
List<int> is a list that only allows integer values andnull`.
You can add such Type parameters to your custom classes as well.
Usually single upper-case letters are used for type parameter names like T, U, K but they can be other names like TKey ...
class MyClass<T> {
T value;
MyClass(this.value);
}
main() {
var mcInt = MyClass<int>(5);
var mcString = MyClass<String>('foo');
var mcStringError = MyClass<String>(5); // causes error because `5` is an invalid value when `T` is `String`
}
See also https://www.dartlang.org/guides/language/language-tour#generics
for example If you intend for a list to contain only strings, you can declare it as List<String> (read that as “list of string”)
I want to parse all names from a random text. Names will be formatted like this:
Lastname F.
where F - first letter of first name. So, I created this grammar:
grammar org.xtext.example.mydsl.Article with org.eclipse.xtext.common.Terminals
generate article "http://www.xtext.org/example/mydsl/Article"
Model : {Model}((per += Person)|(words += NON_WS))*;
Person : lastName = NAME firstName = IN;
terminal NAME : ('A'..'Z')('a'..'z')+;
terminal IN : ('A'..'Z')'.';
terminal NON_WS : !(' '|'\t'|'\r'|'\n')+;
It works on this example:
Lastname F. some text. Lastname F.
But it crashes on this one:
Lastname F. some text. New sentence. Lastname F.
^^^^^^^^^ missing RULE_IN at 'sentence.'
How do I include a checking of all tokens before the generation of the 'Person' object or before the entering the 'Person' rule?
lexing is done kontext free. thus one lexed a name, always lexed a name
Model : {Model}((per += Person)|(words += (NON_WS|NAME)))*;
I working on somebody's dataset in Stata that uses dummy variables to indicate the subject id like the following:
variable name variable label
country_dummy1 Afghanistan
country_dummy2 Albania
country_dummy3 Algeria
...
This makes the dataset very hard to work with and I am trying to generate a subject id variable (country) from the dummies to look like this
country country_dummy1 country_dummy2 country_dummy3
Afghanistan 1 0 0
Albania 0 1 0
Algeria 0 0 1
I wrote the following command:
gen country = "."
foreach x of varlist country_dummy1-country_dummy175 {
local z : variable label `x'
replace country = `z' if `x'==1
}
Stata produced the following error message:
Afghanistan not found
r(111);
I have not been able to identify why this occurred.
You need
gen country = ""
foreach x of varlist country_dummy1-country_dummy175 {
local z : variable label `x'
replace country = "`z'" if `x'==1
}
Note that Stata does not treat "." as a missing string value. Your error was that if you do not specify that you want a literal string with "" then Stata will look for a variable with the name you specify. In your case, Afghanistan would be a legal variable name, but you have no such variable: hence the error. Countries with spaces in their names would be problematic for other reasons as well, but the command would almost always fail for the same reason.
This should work too:
gen country = ""
foreach x of varlist country_dummy1-country_dummy175 {
replace country = "`: variable label `x''" if `x'
}
You could slap quietly on the foreach to avoid 175 messages from the replace.