LIFO (Last-In, First-Out) precedence of rules with overlapping anchors.
ID: 1265
See: uCalc Transformer
using uCalcSoftware;
var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
var text = "An apple, an apple pie, and an apple cider.";
// Rule 1 (Lowest precedence for this anchor)
t.FromTo("an apple", "[FRUIT]");
// Rule 2 (Higher precedence)
t.FromTo("an apple pie", "[DESSERT]");
// The transformer will match "an apple pie" first because it was defined last.
// For the remaining "an apple" occurrences, it will fall back to the first rule.
Console.WriteLine(t.Transform(text));
};
[FRUIT], [DESSERT], and [FRUIT] cider. using uCalcSoftware; var uc = new uCalc(); using (var t = new uCalc.Transformer()) { var text = "An apple, an apple pie, and an apple cider."; // Rule 1 (Lowest precedence for this anchor) t.FromTo("an apple", "[FRUIT]"); // Rule 2 (Higher precedence) t.FromTo("an apple pie", "[DESSERT]"); // The transformer will match "an apple pie" first because it was defined last. // For the remaining "an apple" occurrences, it will fall back to the first rule. Console.WriteLine(t.Transform(text)); };
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
{
uCalc::Transformer t;
t.Owned(); // Causes t to be released when it goes out of scope
auto text = "An apple, an apple pie, and an apple cider.";
// Rule 1 (Lowest precedence for this anchor)
t.FromTo("an apple", "[FRUIT]");
// Rule 2 (Higher precedence)
t.FromTo("an apple pie", "[DESSERT]");
// The transformer will match "an apple pie" first because it was defined last.
// For the remaining "an apple" occurrences, it will fall back to the first rule.
cout << t.Transform(text) << endl;
};
}
[FRUIT], [DESSERT], and [FRUIT] cider. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::Transformer t; t.Owned(); // Causes t to be released when it goes out of scope auto text = "An apple, an apple pie, and an apple cider."; // Rule 1 (Lowest precedence for this anchor) t.FromTo("an apple", "[FRUIT]"); // Rule 2 (Higher precedence) t.FromTo("an apple pie", "[DESSERT]"); // The transformer will match "an apple pie" first because it was defined last. // For the remaining "an apple" occurrences, it will fall back to the first rule. cout << t.Transform(text) << endl; }; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using t As New uCalc.Transformer()
Dim text = "An apple, an apple pie, and an apple cider."
'// Rule 1 (Lowest precedence for this anchor)
t.FromTo("an apple", "[FRUIT]")
'// Rule 2 (Higher precedence)
t.FromTo("an apple pie", "[DESSERT]")
'// The transformer will match "an apple pie" first because it was defined last.
'// For the remaining "an apple" occurrences, it will fall back to the first rule.
Console.WriteLine(t.Transform(text))
End Using
End Sub
End Module
[FRUIT], [DESSERT], and [FRUIT] cider. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using t As New uCalc.Transformer() Dim text = "An apple, an apple pie, and an apple cider." '// Rule 1 (Lowest precedence for this anchor) t.FromTo("an apple", "[FRUIT]") '// Rule 2 (Higher precedence) t.FromTo("an apple pie", "[DESSERT]") '// The transformer will match "an apple pie" first because it was defined last. '// For the remaining "an apple" occurrences, it will fall back to the first rule. Console.WriteLine(t.Transform(text)) End Using End Sub End Module