Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to apply rules of grammar?
Forum Updated to NodeBB v4.3 + New Features

How to apply rules of grammar?

Scheduled Pinned Locked Moved Unsolved General and Desktop
32 Posts 6 Posters 10.6k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BlasterB Blaster

    @mrjj He is a translator of hieroglyphs and I want, for example, in the following text:

    "asddf"
    

    And when applying one of the rules would be

    "asdf"
    

    How do I do it?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @Blaster

    well it really depends on what hieroglyphs can be
    and also what the rules can be ?

    So you have a trigger text like asddf and once found it should look up a rule
    with the text as key and trasnform the selected text with the function ?

    Or what is the overall process?

    BlasterB 1 Reply Last reply
    0
    • mrjjM mrjj

      @Blaster

      well it really depends on what hieroglyphs can be
      and also what the rules can be ?

      So you have a trigger text like asddf and once found it should look up a rule
      with the text as key and trasnform the selected text with the function ?

      Or what is the overall process?

      BlasterB Offline
      BlasterB Offline
      Blaster
      wrote on last edited by
      #5

      @mrjj
      Let me explain myself better.
      I have a fairly large text and after clicking on a button, the application should apply the rules to the text, and I say the rules because it is not one are several.
      What makes it difficult is that the rules have to be in a file because they depend on other factors.
      My problems are:
      How do I write the rules in a file so that the application can understand them?
      How, after reading them, do I apply them to my text?

      mrjjM 1 Reply Last reply
      0
      • BlasterB Blaster

        @mrjj
        Let me explain myself better.
        I have a fairly large text and after clicking on a button, the application should apply the rules to the text, and I say the rules because it is not one are several.
        What makes it difficult is that the rules have to be in a file because they depend on other factors.
        My problems are:
        How do I write the rules in a file so that the application can understand them?
        How, after reading them, do I apply them to my text?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @Blaster
        But how is your rule defined?
        That will determine how u can save them.

        Can you show 1 rule?

        BlasterB 1 Reply Last reply
        1
        • mrjjM mrjj

          @Blaster
          But how is your rule defined?
          That will determine how u can save them.

          Can you show 1 rule?

          BlasterB Offline
          BlasterB Offline
          Blaster
          wrote on last edited by
          #7

          @mrjj
          I already told you that I do not know how to express them, but in principle, the one I set as an example, would be:
          xx -> x
          xyxy -> xy
          I don't know, something like that

          mrjjM 1 Reply Last reply
          0
          • BlasterB Blaster

            @mrjj
            I already told you that I do not know how to express them, but in principle, the one I set as an example, would be:
            xx -> x
            xyxy -> xy
            I don't know, something like that

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @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?

            BlasterB 1 Reply Last reply
            0
            • mrjjM mrjj

              @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?

              BlasterB Offline
              BlasterB Offline
              Blaster
              wrote on last edited by
              #9

              @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 express

              mrjjM 1 Reply Last reply
              0
              • BlasterB Blaster

                @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 express

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @Blaster

                Well one way is just to use name for what function to call

                TriggerText, Action, Param1
                afffd, one_occurrence, none
                HHH, text_replace, thetext

                This 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.

                BlasterB 1 Reply Last reply
                1
                • mrjjM mrjj

                  @Blaster

                  Well one way is just to use name for what function to call

                  TriggerText, Action, Param1
                  afffd, one_occurrence, none
                  HHH, text_replace, thetext

                  This 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.

                  BlasterB Offline
                  BlasterB Offline
                  Blaster
                  wrote on last edited by
                  #11

                  @mrjj
                  It's a good idea, but what I want is not having to write a function for each rule

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #12

                    @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

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    BlasterB 1 Reply Last reply
                    2
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #13

                      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.

                      kshegunovK BlasterB 2 Replies Last reply
                      3
                      • ? A Former User

                        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.

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #14

                        @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. :)

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        1
                        • ? A Former User

                          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.

                          BlasterB Offline
                          BlasterB Offline
                          Blaster
                          wrote on last edited by
                          #15

                          @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

                          ? 1 Reply Last reply
                          0
                          • BlasterB Blaster

                            @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

                            ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #16

                            @Blaster https://en.wikipedia.org/wiki/Context-free_grammar, https://en.wikipedia.org/wiki/Backus–Naur_form

                            BlasterB 1 Reply Last reply
                            1
                            • VRoninV VRonin

                              @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

                              BlasterB Offline
                              BlasterB Offline
                              Blaster
                              wrote on last edited by
                              #17

                              @VRonin
                              In this case ... how do I make the regular expression capture the occurrence of equal letters without defining what the letter

                              1 Reply Last reply
                              0
                              • BlasterB Blaster

                                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?

                                VRoninV Offline
                                VRoninV Offline
                                VRonin
                                wrote on last edited by VRonin
                                #18

                                @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?

                                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                ~Napoleon Bonaparte

                                On a crusade to banish setIndexWidget() from the holy land of Qt

                                BlasterB 1 Reply Last reply
                                1
                                • VRoninV VRonin

                                  @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?

                                  BlasterB Offline
                                  BlasterB Offline
                                  Blaster
                                  wrote on last edited by
                                  #19

                                  @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

                                  VRoninV 1 Reply Last reply
                                  0
                                  • ? A Former User

                                    @Blaster https://en.wikipedia.org/wiki/Context-free_grammar, https://en.wikipedia.org/wiki/Backus–Naur_form

                                    BlasterB Offline
                                    BlasterB Offline
                                    Blaster
                                    wrote on last edited by
                                    #20

                                    @Wieland
                                    It is not grammar free of context, it is a gramática similar to the one of our languages

                                    1 Reply Last reply
                                    0
                                    • VRoninV Offline
                                      VRoninV Offline
                                      VRonin
                                      wrote on last edited by
                                      #21

                                      Imagine the input is xxxyxy do you want the output to be xxy or xy?

                                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                      ~Napoleon Bonaparte

                                      On a crusade to banish setIndexWidget() from the holy land of Qt

                                      BlasterB 1 Reply Last reply
                                      0
                                      • VRoninV VRonin

                                        Imagine the input is xxxyxy do you want the output to be xxy or xy?

                                        BlasterB Offline
                                        BlasterB Offline
                                        Blaster
                                        wrote on last edited by
                                        #22

                                        @VRonin
                                        Just xy

                                        1 Reply Last reply
                                        0
                                        • VRoninV Offline
                                          VRoninV Offline
                                          VRonin
                                          wrote on last edited by VRonin
                                          #23

                                          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;
                                          }
                                          

                                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                          ~Napoleon Bonaparte

                                          On a crusade to banish setIndexWidget() from the holy land of Qt

                                          BlasterB 1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved