setting feature value to zero for some instance in uima ruta - uima

I'm able to set the feature value for the DZC_FigureCitation annotation
Currently I'm able to match and set feature value (chapter and section) Figure 1.1.I also need to match and set feature value (chapter=0 and section) for Figure 1.
Sample Input:
Figure 1.1
Figure 1.2
Figure 1
Figure 2.3
Figure 2
Script:
MayBeFigure (COLON|PERIOD)? NUM? (SPECIAL|PERIOD)? NUM{-> MARK(ChapterNumber,3),MARK(FigureNumber,5), MARK(FigureCitation, 1, 5),MARK(FIGURE,1)};
MayBeFigure{-PARTOF(FIGURE)} (COLON|PERIOD)? NUM{-PARTOF(ChapterNumber),-PARTOF(FigureCitation) -> MARK(FigureNumber,3),MARK(FigureCitation,1,3),MARK(FIGURE,1)};
BLOCK (foreach) FigureCitation {}
{
DECLARE DZC_FigureCitation(INT chapter,INT section);
ACTION FCC(INT chap,INT sect) = CREATE(DZC_FigureCitation, "chapter" = chap, "section" = sect);
INT Figchap=0;
INT Figsec;
(FIGURE (COLON|PERIOD)? ChapterNumber?{PARSE(Figchap)}(PERIOD|HYPHEN)? #FigureNumber{PARSE(Figsec)}){-PARTOF(DZC_FigureCitation),-PARTOF(DZC_SupplFigureCitation)-> FCC(Figchap,Figsec)};
}
Expected Output:
Figure 1.1
chapter:1
section:1
Figure 1.2
chapter:1
section:2
Figure 1
chapter:0
section:1
Figure 2.3
chapter:2
section:3
Figure 2
chapter:0
section:2
Received Output:
Figure 1.1
chapter:1
section:1
Figure 1.2
chapter:1
section:2
Figure 1
chapter:1
section:1
Figure 2.3
chapter:2
section:3
Figure 2
chapter:2
section:2

Variables in UIMA Ruta are global. You need to reset the values within the block loop before your last rule:
Document{-> ASSIGN(Figchap,0),ASSIGN(Figsec,0)};
(FIGURE (COLON|PERIOD)? ChapterNumber?{PARSE(Figchap)}(PERIOD|HYPHEN)? #FigureNumber{PARSE(Figsec)}){-PARTOF(DZC_FigureCitation),-PARTOF(DZC_SupplFigureCitation)-> FCC(Figchap,Figsec)};
DISCLAIMER: I am a developer of UIMA Ruta

MayBeFigure (COLON|PERIOD)? NUM? (SPECIAL|PERIOD)? NUM{-> MARK(ChapterNumber,3),MARK(FigureNumber,5), MARK(FigureCitation, 1, 5),MARK(FIGURE,1)};
MayBeFigure{-PARTOF(FIGURE)} (COLON|PERIOD)? NUM{-PARTOF(ChapterNumber),-PARTOF(FigureCitation) -> MARK(FigureNumber,3),MARK(FigureCitation,1,3),MARK(FIGURE,1)};
DECLARE DZC_FigureCitation(INT chapter,INT section);
ACTION FCC(INT chap,INT sect) = CREATE(DZC_FigureCitation, "chapter" = chap, "section" = sect);
BLOCK (foreach) FigureCitation {}
{
INT Figchap;
INT Figsec;
Document{->ASSIGN(Figchap,0)};
Document{->ASSIGN(Figsec,0)};
(FIGURE (COLON|PERIOD)? ChapterNumber?{PARSE(Figchap)}(PERIOD|HYPHEN)? #FigureNumber{PARSE(Figsec)}){-PARTOF(DZC_FigureCitation)-> FCC(Figchap,Figsec)};
}

Related

How do I tell my graph coloring problem program to only assign color 1 one time?

Basically, I have a graph coloring program where each node with an edge to another node has to be different colors. Here, is my code:
node(1..4).
edge(1,2).
edge(2,3).
edge(3,4).
edge(4,1).
edge(2,4).
color(1..3).
{ assign(N,C) : color(C) } = 1 :- node(N).
1 { assign(N,1) : color(1) } 1 :- node(N). %line in question
:- edge(N,M), assign(N,C), assign(M,C).
How would I tell the program to only assign color 1, once? The line labeled %line in question is the line giving me problems. Here is another solution I tried that didn't work:
node(1..4).
edge(1,2).
edge(2,3).
edge(3,4).
edge(4,1).
edge(2,4).
color(1..3).
{ assign(N,C) : color(C) } = 1 :- node(N).
:- edge(N,M), assign(N,C), assign(M,C).
vtx(Node, Color) :- node(Node), color(Color).
1 { vtx(N, 1) : color(1) } 1 :- node(N).
#show vtx/2.
If anyone could help me out it would be much appreciated.
In this simple case of restricting a single color to be used once, you can write the a single constraint
:- assign(N, 1), assign(M, 1), node(N), node(M), N!=M.
Actually, the line you marked as in question :
1 { assign(N,1) : color(1) } 1 :- node(N). %line in question
can be translated as
If N is a node, we will (and we must) assign color(1) to node(N) and only assign once, i.e. If node(i) is true, we will have exactly one node(i, 1).
Therefore, with this rule and your facts node(1..4), you will immediately get assign(1,1), assign(2,1), assign(3,1), assign(4,1). This is defninitely unsatisfiable under color problem (with the last constraint).
Back to your requirement:
How would I tell the program to only assign color 1, once?
The problem here is the constraint you set in the line: "color 1 is assigned only once" applies to each node(i), i=1,2,3,4 instead of all nodes.
To make it clearer, you might as well consider that this line would be instantiated as:
1 { assign(1,1) : color(1) } 1 :- node(1).
1 { assign(2,1) : color(1) } 1 :- node(2).
1 { assign(3,1) : color(1) } 1 :- node(3).
1 { assign(4,1) : color(1) } 1 :- node(4).
With node(1..4) all true, we will have assign(1,1), assign(2,1), assign(3,1), assign(4,1).
What you want is assign(N, 1) appears once and only once in the answer, thus in your rule, this should be true with no premiere condition.
Therefore, change the problem line into:
{ assign(N,1): node(N), color(1) } = 1. %problem line changed
You will get the proper assignment:
clingo version 5.4.0
Reading from test.lp
Solving...
Answer: 1
assign(2,2) assign(1,3) assign(3,3) assign(4,1)
Answer: 2
assign(1,2) assign(2,3) assign(3,2) assign(4,1)
Answer: 3
assign(2,1) assign(1,3) assign(3,3) assign(4,2)
Answer: 4
assign(2,1) assign(1,2) assign(3,2) assign(4,3)
SATISFIABLE
Intuitively, this line means the assign(N, 1) should be in answer set under no condition, as long as N is a node. This will count all nodes instead of every single one.

Depth First Search Implementation - understanding swift code

I was going thru few tutorials for Tree DS and I found this code which is really confusing to understand. Please explain
public func forEachDepthFirst(visit: (TreeNode) -> Void) {
visit(self) // 1
children.forEach { // 2
$0.forEachDepthFirst(visit: visit)
}
}
}
Why do we have visit(self) here?
I see explanation here https://forums.raywenderlich.com/t/help-understanding-the-recursion-for-depth-first-traversal/56552/2 but its still not clear
Any recusive method has
1- base case : which ends the run and here it's
children.forEach // when children property is empty meaning a leaf node
2- recusive case
$0.forEachDepthFirst(visit: visit) // call the same method with it's children
Your method takes a closure / completion that's be called for every node inside the main root node
So suppose You have root
0
- 1
- 1.1 , 1.2 , 1.3
- 2
- 2.1 , 2.2 , 2.3
Here 0 node is called then when runnign your function
visit(0)
children.forEach { // = 1,2
for 0 > 1
visit(1)
children.forEach { // = 1.1,1.2,1.3
for 0 > 2
visit(2)
children.forEach { // = 2.1,2.2,2.3
Inner case
for 0 > 1 > 1.1
visit(1.1)
children.forEach { // end here as there is no childrens ( leaf node)
so on for 1.2,1,3
for 0 > 2 > 2.1 / 2.2 / 2.3 same as above case
How to call
your method is an instance method inside the tree so every node can call it , if you want to traverse nodes of 0 then do this
zeroNode.forEachDepthFirst { (item) in
print(item.name) // suppose node object has a name
}
Then you will get
0 , 1 , 1.1 , 1.2 , 1.3 , 2.1 , 2.2 , 2.3
And that's as you called visit(NodeObject) for the main node and recursively all it's childrens
Why do we have visit(self) here?
Because if we didn't, we would never actually do anything to any of the nodes on the tree!
Consider this tree:
n1 -> n2 -> n3 -> n4
We now call our method forEachDepthFirst on n1. If we didn't have visit(self), we would immediately call forEachDepthFirst on n2, which would call it on n3, which would call it on n4. And then we'd stop. But at no time would we have called visit, so we would have looped through every node in the tree without doing anything to those nodes.

An issue with argument "sortv" of function seqIplot()

I'm trying to plot individual sequences by means of function seqIplot() in TraMineR. These individual sequences represent work trajectories, completed by former school's graduates via a WEB questionnaire.
Using argument "sortv", I'd like to sort my sequences according to the order of the levels of one covariate, the year of graduation, named "PROMO".
"PROMO" is a factor variable contained in a data frame named "covariates.seq", gathering covariates together:
str(covariates.seq)
'data.frame': 733 obs. of 6 variables:
$ ID_SQ : Factor w/ 733 levels "1","2","3","5",..: 1 2 3 4 5 6
7 8 9 10 ...
$ SEXE : Factor w/ 2 levels "Féminin","Masculin": 1 1 1 1 2 1
1 2 2 1 ...
$ PROMO : Factor w/ 6 levels "1997","1998",..: 1 2 2 4 4 3 2 2
2 2 ...
$ DEPARTEMENT : Factor w/ 10 levels "BC","GCU","GE",..: 1 4 7 8 7 9
9 7 7 4 ...
$ NIVEAU_ADMISSION: Factor w/ 2 levels "En Premier Cycle",..: NA 1 1 1 1
1 NA 1 1 1 ...
$ FILIERE_SECTION : Factor w/ 4 levels "Cursus Classique",..: NA 4 2 NA
1 1 NA NA 4 3 ..
I'm also using "SEXE", the graduates' gender, as a grouping variable. To plot the individual sequences so, my command is as follows:
seqIplot(sequences, group = covariates.seq$SEXE,
sortv = covariates.seq$PROMO,
cex.axis = 0.7, cex.legend = 0.7)
I expected that, by using a process time axis (with the year of graduation as sequence-dependent origin), sorting the sequences according to the order of the levels of "PROMO" would give a plot with groups of sequences from the longest (for the older graduates) to the shortest (for the younger graduates).
But I've got an issue: in the output plot, the sequences don't appear to be correctly sorted according to the levels of "PROMO". Indeed, by using "sortv = covariates.seq$PROMO" as in the command above, the plot doesn't show groups of sequences from the longest to the shortest, as expected. It looks like the plot obtained without using the argument "sortv" (see Figures below).
Without using argument "sortv"
Using "sortv = covariates.seq$PROMO"
Note that I have 733 individual sequences in my object "sequences", created as follows:
labs <- c("En poste","Au chômage (d'au moins 6 mois)", "Autre situation
(d'au moins 6 mois)","En poursuite d'études (thèse ou hors
thèse)", "En reprise d'études / formation (d'au moins 6 mois)")
codes <- c("En poste", "Au chômage", "Autre situation", "En poursuite
d'études", "En reprise d'études / formation")
sequences <- seqdef(situations, alphabet = labs, states = codes, left =
NA, right = "DEL", missing = NA,
cnames = as.character(seq(0,7400/365,1/365)),
xtstep = 365)
The values of the covariates are sorted in the same order as the individual sequences. The covariate "PROMO" doesn't contain any missing value.
Something's going wrong, but what?
Thank you in advance for your help,
Best,
Arnaud.
Using a factor as sortv argument in seqIplot works fine as illustrated by the example below:
sdc <- c("aabbccdd","bbbccc","aaaddd","abcabcab")
sd <- seqdecomp(sdc, sep="")
seq <- seqdef(sd)
fac <- factor(c("2000","2001","2001","2000"))
par(mfrow=c(1,3))
seqIplot(seq, with.legend=FALSE)
seqIplot(seq, sortv=fac, with.legend=FALSE)
seqlegend(seq)

Can't remove whitespace in rythm engine

I am using the rythmengine.
The output I want is: x=prefix:value without any whitespaces.
#def test(String param){
#{param="prefix:"+param} #param
}
1
2 x=#test("value")
3
output is: 2 x= prefix:value
#def test(String param){
#{param="prefix:"+param}#param
}
1
2 x=#test("value")
3
output is: 2 x=param
This seems like a bug. Does anyone know a solution or workaround?
Try the following code on http://fiddle.rythmengine.org/#/editor:
#def test(String param){
#{param="prefix:"+param}##param
}
1
2 x=#test("value")
3

Display Superscript in SSRS reports

I m working on SSRS 2008.
i want to display date as 1st January 2011..
but "st" should be in superscipt ..
not like "1st".
is there any way to display "st", "nd","rd" and "th" in superscipt without installing any custom font type(other Font Type).
just copy and paste from the following list:
ABC⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁺ ⁻ ⁼ ⁽ ⁾
ABC₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ₊ ₋ ₌ ₍ ₎
ABCᵃ ᵇ ᶜ ᵈ ᵉ ᶠ ᵍ ʰ ⁱ ʲ ᵏ ˡ ᵐ ⁿ ᵒ ᵖ ʳ ˢ ᵗ ᵘ ᵛ ʷ ˣ ʸ ᶻ
ABCᴬ ᴮ ᴰ ᴱ ᴳ ᴴ ᴵ ᴶ ᴷ ᴸ ᴹ ᴺ ᴼ ᴾ ᴿ ᵀ ᵁ ᵂ
ABCₐ ₑ ᵢ ₒ ᵣ ᵤ ᵥ ₓ
ABC½ ¼ ¾ ⅓ ⅔ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ № ℠ ™ © ®
ABC^ ± ¶
Maybe...
You are limited to what can be done with String.Format. Font size and spacing also refer to the whole text box. So it isn't "native"
However, superscript is unicode so you may be able to to do it with some fancy expression that concatenate characters. I'd suggest custom code.
I haven't tried this, but these articles mention it
http://beyondrelational.com/blogs/jason/archive/2010/12/06/subscripts-and-superscripts-in-ssrs-reports.aspx
http://www.codeproject.com/KB/reporting-services/SSRSSuperscript.aspx
I am not looking for credit here as above solution has answered it for you but for beginners sake, I use a code function within my report.
So in my SQL say I have Number field, then I add a new field OrdinalNumber:
SELECT ..., Number,
CASE WHEN (Number % 100) BETWEEN 10 AND 20 THEN 4
WHEN (Number % 10) = 1 THEN 1
WHEN (Number % 10) = 2 THEN 2
WHEN (Number % 10) = 3 THEN 3
ELSE 4 END AS OrdinalNumber,
...
Then my code function:
Function OrdinalText(ByVal OrdinalNumber As Integer) As String
Dim result As String
Select Case OrdinalNumber
Case 1
result = "ˢᵗ"
Case 2
result = "ⁿᵈ"
Case 3
result = "ʳᵈ"
Case Else
result = "ᵗʰ"
End Select
Return result
End Function
Then in the report textbox I use the expression:
=CStr(Fields!Number.Value) & Code.OrdinalText(Fields!OrdinalNumber.Value)