title: classify text using 'from text' and 'to text' in the dataframe in R
body: <p>Here is my toy data (Note that in my original data, I have 100s of rule sets i.e. such from to combinations):</p>
  <pre><code>rule_set &lt;- tibble::tribble(
        ~if_you_see,  ~write,
      &quot;honda civic&quot;,   &quot;car&quot;,
    &quot;toyota camery&quot;,   &quot;car&quot;,
        &quot;honda CRV&quot;,   &quot;car&quot;,
              &quot;boy&quot;, &quot;human&quot;,
             &quot;girl&quot;, &quot;human&quot;)
  </code></pre>
  <p>Following is the dataframe with the text to be classified using the rule set in the above data frame. So, if you see the car names (given in the above data frame) in the below text, you write 'car' and if you see the entries boy or girl, you write 'human'.</p>
  <pre><code>to_be_classified &lt;- tibble::tribble(
                                          ~text,
         &quot;I have a honda civic. It pretty good.&quot;,
    &quot;The toyota camery is also good. I like it&quot;,
                     &quot;That boy has a honda CRV.&quot;,
             &quot;You see that girl in blue dress?&quot;)
  </code></pre>
  <p>Here is the desired output:</p>
  <pre><code>desired_output &lt;- tibble::tribble(
                                          ~text,       ~class,
         &quot;I have a honda civic. It pretty good.&quot;,        &quot;car&quot;,
    &quot;The toyota camery is also good. I like it&quot;,        &quot;car&quot;,
                    &quot;That boy has a honda CRV.&quot;, c(&quot;human, car&quot;),
             &quot;You see that girl in blue dress?&quot;,      &quot;human&quot;)
  </code></pre>
  <p>I started thinking on the following lines, but could not move forward.</p>
  <pre><code>library(tidyverse)
  to_be_classified %&gt;% 
        mutate(class = if_else(str_detect(text, pattern = rule_set$if_you_see), if_you_see$write))
  </code></pre>
  <p>Please advise, preferably with code involving dplyr and stringr functions.</p>