title: Tagging part of speech for a particular word in R
body: <p>I have a column A having sentences and column B have some words. I want to check the part of speech column B word belongs to sentence present in column A.</p>
  
  <p>Currently I am able to get part of speech for a single sentence using following code:</p>
  
  <p>I am trying to get part of speech corresponds to each sentence in text file. Please suggest code for this.</p>
  
  <pre><code>s &lt;- unlist(lapply(posText, function(x) { str_split(x, "\n") }))
  
  tagPOS &lt;-  function(x, ...) {
    s &lt;- as.String(x)
    word_token_annotator &lt;- Maxent_Word_Token_Annotator()
    a2 &lt;- Annotation(1L, "sentence", 1L, nchar(s))
    a2 &lt;- annotate(s, word_token_annotator, a2)
    a3 &lt;- annotate(s, Maxent_POS_Tag_Annotator(), a2)
    a3w &lt;- a3[a3$type == "word"]
    POStags &lt;- unlist(lapply(a3w$features, `[[`, "POS"))
    POStagged &lt;- paste(sprintf("%s/%s", s[a3w], POStags), collapse = " ")
    list(POStagged = POStagged, POStags = POStags)
  }
  
  tagged_str &lt;-  tagPOS(s)
  </code></pre>