Hello, All,
our current problem is following: we're recognizing documents with tens possible different kinds of data tables,
that means both table structure (location of fields among each other) and fields' format, and we have a collection of
repeatable group " templates" and expect the correct "template" would produce more instances than any "wrong"
"template" (and the tests confirm it so far).
The question is: how to create a repeatable group, made of "region" elements, that would just copy the "best" repeatable
group (one with most instances) in FlexiLayout Studio, so we could see the dynamically selected group? What could be
the most elegant solution? Maybe using "Hypothesis" or "HypothesisInstances" variables? Or the only solution is storing
found Rects in variables and using them afterwards?
our current problem is following: we're recognizing documents with tens possible different kinds of data tables,
that means both table structure (location of fields among each other) and fields' format, and we have a collection of
repeatable group " templates" and expect the correct "template" would produce more instances than any "wrong"
"template" (and the tests confirm it so far).
The question is: how to create a repeatable group, made of "region" elements, that would just copy the "best" repeatable
group (one with most instances) in FlexiLayout Studio, so we could see the dynamically selected group? What could be
the most elegant solution? Maybe using "Hypothesis" or "HypothesisInstances" variables? Or the only solution is storing
found Rects in variables and using them afterwards?
Comments
3 comments
Let you have 3 repeating groups: rg1, rg2, rg3. And you need to choose from them the best one and assign as a source element for the repeating group block. As I understood, in your case “the best one” = “one that has the maximal number of instances”.
As a first variant, you indeed can create an auxiliary repeating group ( let it be “rgFinal” ) and use this group as a block source. This group will contain region elements. Advanced pre-search relations for the elements can be like the following:
//========================
Int i = InstancesCount; // Will be N-1 for instance number N
Int MaxInstCount = Max( rg1.InstancesCount, Max( rg2.InstancesCount, rg3.InstancesCount ) );
Rect R = DocumentRect;
If i < maxinstcount="" and="" maxinstcount=""> 0 Then {
If MaxInstCount = = rg1.InstancesCount Then {
R = rg1.Instance( i + 1 ).NeededElementName.Rect;
}
Else If MaxInstCount = = rg2.InstancesCount Then {
R = rg2.Instance( i + 1 ).NeededElementName.Rect;
}
Else {
R = rg3.Instance( i + 1 ).NeededElementName.Rect;
}
}
Else {
DontFind;
}
RestrictSearchArea: R;
//========================
Similar pre-search relation should be specified in each child element of your auxiliary repeating group.
Another approach would be using region expressions in repeating group blocks and all child blocks. In this case an auxiliary repeating group is not needed.
In the repeating group block the expression can be like the following:
//============
Int MaxInstCount = Max( rg1.InstancesCount, Max( rg2.InstancesCount, rg3.InstancesCount ) );
If MaxInstCount == rg1.InstancesCount Then {
OutputInstances = rg1.AllInstances;
}
Else If MaxInstCount = = rg2.InstancesCount Then {
OutputInstances = rg2.AllInstances;
}
Else {
OutputInstances = rg3.AllInstances;
}
//============
The similar code should be specified in each child of the repeating group block. The only change is that instead of rgN.AllInstances you should use rgN.AllInstances.SubelementName.
thanks for your reply, it seems to be a good working solution. I tried storing each found Rect of each table candidate in a RectArray, but that approach would require more memory than this one.
But isn't it possible to solve this task through Hypothesis or HypothesisInstances data types? Could these types be even used in the scripts?
Thanks, Yury
In my sample with region expression the predefined variable OutputInstances has type HypothesisInstances in case of repeating text and TableHypothesisInstances in case of repeating table. Regarding Hypothesis data type, let you are searching for a character string relative to previously found static text. In pre-search relations of character string you may use a code like the following:
// ********************
Let H = stHeader; // static text name
If H.IsNull Then {
DontFind;
}
Else {
Above: H.Bottom + H.Height / 2;
Below: H.Top - H.Height / 2;
RightOf: H;
Nearest: H;
}
// ********************
In this example variable H has type Hypothesis. I could also declare it as Hypothesis H = stHeader, if only static text stHeader has no user-defined properties ( code section just above pre-search relations ). Otherwise declaration is possible via Let only, because generated hypothesis for an element with user-defined properrties is actually an extension of Hypothesis data type.
Please sign in to leave a comment.