How to apply rules of grammar?
-
@Blaster
well im asking you to express a rule in english :)If only action is text replacement then format could be
Text to find, text to replace tp
but i not sure what rules can be.
A rule is only Text To Find, Text to replace with or is a rule something else?
-
@mrjj
There are other rules and it is not just text to replace. The idea of this rule is to find the occurrence of consecutive patterns and leave only one occurrence, which is what I find difficult to expressWell one way is just to use name for what function to call
TriggerText, Action, Param1
afffd, one_occurrence, none
HHH, text_replace, thetextThis is epic esy to read in with Qt.
But I would first write up all rules and what data it needs to operate.
That would give you idea on what format is needed. -
Well one way is just to use name for what function to call
TriggerText, Action, Param1
afffd, one_occurrence, none
HHH, text_replace, thetextThis is epic esy to read in with Qt.
But I would first write up all rules and what data it needs to operate.
That would give you idea on what format is needed. -
@Blaster said in How to apply rules of grammar?:
The idea of this rule is to find the occurrence of consecutive patterns and leave only one occurrence
put the patterns in a file, one by line. for each line do a replace with QRegularExpression replacing
"(?:%1)+"
with"%1"
where %1 is the pattern -
Hi! Don't know anything about hieroglyphs, but if the language they represent has a context-free grammar, then you can express the rules in Backus-Naur form and process the source text with Flex and Bison.
-
Hi! Don't know anything about hieroglyphs, but if the language they represent has a context-free grammar, then you can express the rules in Backus-Naur form and process the source text with Flex and Bison.
@Wieland said in How to apply rules of grammar?:
if the language they represent has a context-free grammar
I have not encountered a natural (i.e. human) language that can be prescribed by a context-free grammar. Otherwise I completely agree, for what it's worth. :)
-
Hi! Don't know anything about hieroglyphs, but if the language they represent has a context-free grammar, then you can express the rules in Backus-Naur form and process the source text with Flex and Bison.
@Wieland said in How to apply rules of grammar?:
Hi! Don't know anything about hieroglyphs, but if the language they represent has a context-free grammar, then you can express the rules in Backus-Naur form and process the source text with Flex and Bison
An example please
-
@Wieland said in How to apply rules of grammar?:
Hi! Don't know anything about hieroglyphs, but if the language they represent has a context-free grammar, then you can express the rules in Backus-Naur form and process the source text with Flex and Bison
An example please
-
@Blaster said in How to apply rules of grammar?:
The idea of this rule is to find the occurrence of consecutive patterns and leave only one occurrence
put the patterns in a file, one by line. for each line do a replace with QRegularExpression replacing
"(?:%1)+"
with"%1"
where %1 is the pattern -
Hello, I'm doing a text editor and I want to apply grammar rules to it. Any idea how to do it?
I was thinking of loading a file with the rules so I could add rules in an easier way, but I can not think how to do it.
Can anybody help me?@Blaster said in How to apply rules of grammar?:
I was thinking of loading a file with the rules
without defining what the letter
I'm confused now...
let's say you have a UTF-8 text file (
rules.txt
) that contains:x xy
You can use
QString stringToTranslate("xyxyxx"); QFile rulesFile("rules.txt"); if(rulesFile.open(QFile::ReadOnly | QFile::Text)){ QTextStream rulesStream(&rulesFile); rulesStream.setCodec("UTF-8"); QString line; while (stream.readLineInto(&line)) stringToTranslate.replace(QRegularExpression("(?:"+QRegularExpression::escape(line)+")+",line); } qDebug() << "Translated String: "+stringToTranslate;
Is this what you wanted?
-
@Blaster said in How to apply rules of grammar?:
I was thinking of loading a file with the rules
without defining what the letter
I'm confused now...
let's say you have a UTF-8 text file (
rules.txt
) that contains:x xy
You can use
QString stringToTranslate("xyxyxx"); QFile rulesFile("rules.txt"); if(rulesFile.open(QFile::ReadOnly | QFile::Text)){ QTextStream rulesStream(&rulesFile); rulesStream.setCodec("UTF-8"); QString line; while (stream.readLineInto(&line)) stringToTranslate.replace(QRegularExpression("(?:"+QRegularExpression::escape(line)+")+",line); } qDebug() << "Translated String: "+stringToTranslate;
Is this what you wanted?
@VRonin
What I really want to know is how to make a regular expression that checks the multiple occurrence of any pattern, not including some specific character in the expression.
Something like, for example"x{2,}"
that would match any string containing 2 or more repeated characters regardless of the character
-
-
I know it's very inefficient but my brain can't optimise on Monday. At least it works:
QString removeDuplicates(QString source){ for(int matchLen = source.size()/2; matchLen>0;--matchLen){ for(int startOfset=0;(2*matchLen)+startOfset<=source.size();){ if(source.midRef(startOfset,matchLen)==source.midRef(matchLen+startOfset,matchLen)) source.remove(matchLen+startOfset,matchLen); else ++startOfset; } } return source; }
-
I know it's very inefficient but my brain can't optimise on Monday. At least it works:
QString removeDuplicates(QString source){ for(int matchLen = source.size()/2; matchLen>0;--matchLen){ for(int startOfset=0;(2*matchLen)+startOfset<=source.size();){ if(source.midRef(startOfset,matchLen)==source.midRef(matchLen+startOfset,matchLen)) source.remove(matchLen+startOfset,matchLen); else ++startOfset; } } return source; }
-
@VRonin
I appreciate the effort, but I need to avoid using functions and that's why I'm talking about regular expressions. The code before the last one helps a lot.@Blaster said in How to apply rules of grammar?:
but I need to avoid using functions
I'm confused... can I ask why?
The code before the last one helps a lot
QString stringToTranslate("zxxxyxyxyxxzz"); for(int matchLen = stringToTranslate.size()/2; matchLen>0;--matchLen){ for(int startOfset=0;(2*matchLen)+startOfset<=stringToTranslate.size();){ if(stringToTranslate.midRef(startOfset,matchLen)==stringToTranslate.midRef(matchLen+startOfset,matchLen)) stringToTranslate.remove(matchLen+startOfset,matchLen); else ++startOfset; } } qDebug() << "Translated String: "+stringToTranslate;
-
@Blaster said in How to apply rules of grammar?:
but I need to avoid using functions
I'm confused... can I ask why?
The code before the last one helps a lot
QString stringToTranslate("zxxxyxyxyxxzz"); for(int matchLen = stringToTranslate.size()/2; matchLen>0;--matchLen){ for(int startOfset=0;(2*matchLen)+startOfset<=stringToTranslate.size();){ if(stringToTranslate.midRef(startOfset,matchLen)==stringToTranslate.midRef(matchLen+startOfset,matchLen)) stringToTranslate.remove(matchLen+startOfset,matchLen); else ++startOfset; } } qDebug() << "Translated String: "+stringToTranslate;
-
@VRonin
What I really want to know is how to make a regular expression that checks the multiple occurrence of any pattern, not including some specific character in the expression.
Something like, for example"x{2,}"
that would match any string containing 2 or more repeated characters regardless of the character
@Blaster said in How to apply rules of grammar?:
how to make a regular expression that checks the multiple occurrence of any pattern
@Blaster said in How to apply rules of grammar?:
because I can put in the file all the combinations and then apply them to the string
I'm totally lost now. If somebody else has ideas please step forward
-
@Blaster said in How to apply rules of grammar?:
how to make a regular expression that checks the multiple occurrence of any pattern
@Blaster said in How to apply rules of grammar?:
because I can put in the file all the combinations and then apply them to the string
I'm totally lost now. If somebody else has ideas please step forward
@VRonin
Let's see, I am Cuban guy and my English is not very strong, I only defend a little.
I explain to you better so you understand.
I have an application in which it is necessary to apply certain rules, one of which I mentioned to you, that of the patterns. This application does not work only in a language and I need to make that the processing of the rules be independent of the language of the application, so I need the rules in a file to be able to make changes when you want to change in some rules or to be able to add a new rule without having to program again