How to generate bi/tri-grams using spacy/nltk
<p>The input text are always list of dish names where there are 1~3 adjectives  and a noun</p>

<p>Inputs</p>

<pre><code>thai iced tea
spicy fried chicken
sweet chili pork
thai chicken curry
</code></pre>

<p>outputs:</p>

<pre><code>thai tea, iced tea
spicy chicken, fried chicken
sweet pork, chili pork
thai chicken, chicken curry, thai curry
</code></pre>

<p>Basically, I am looking to parse the sentence tree and try to generate bi-grams by pairing an adjective with the noun.</p>

<p>And I would like to achieve this with spacy or nltk</p>

<p>Something like this:</p>

<pre><code>&gt;&gt;&gt; from nltk import bigrams
&gt;&gt;&gt; text = """thai iced tea
... spicy fried chicken
... sweet chili pork
... thai chicken curry"""
&gt;&gt;&gt; lines = map(str.split, text.split('\n'))
&gt;&gt;&gt; for line in lines:
...     ", ".join([" ".join(bi) for bi in bigrams(line)])
... 
'thai iced, iced tea'
'spicy fried, fried chicken'
'sweet chili, chili pork'
'thai chicken, chicken curry'
</code></pre>

<hr>

<p>Alternatively using <code>colibricore</code> <a href="https://proycon.github.io/colibri-core/doc/#installation" rel="nofollow">https://proycon.github.io/colibri-core/doc/#installation</a> ;P</p>

python nlp nltk n-gram spacy