-3

Paragraph 1

Electronic commerce, commonly written as E-Commerce, is the trading or facilitation of trading in goods or services using computer networks, such as the Internet or online social networks. Electronic commerce draws on technologies such as mobile commerce, electronic funds transfer, supply chain management, Internet marketing, online transaction processing, electronic data interchange (EDI), inventory management systems, and automated data collection systems.

Paragraph 2

Modern electronic commerce typically uses the World Wide Web for at least one part of the transaction's life cycle although it may also use other technologies such as e-mail. The benefits of e-commerce include it’s the speed of access, a wider selection of goods and services, accessibility, and international reach.

i have to find common word between two Paragraph's and print them

BMK007
  • 39
  • 6
  • 2
    This sounds like a homework question, so instead of providing an answer I'll give you a hint. NLTK is not able to do this on its own — that's not what NLTk is for. However, most likely what you're needing to do is use NLTK's tokenizer to split the paragraphs into words, and then put those words into sets and compare (e.g. by way of the suggestions from the proposed answers). – Pierce Darragh Aug 04 '17 at 04:33
  • Step 1. `nltk.word_tokenize` , Step 2: see https://stackoverflow.com/questions/15173225/how-to-calculate-cosine-similarity-given-2-sentence-strings-python or try any methods from http://web.stanford.edu/class/linguist236/materials/ling236-handout-05-09-vsm.pdf – alvas Aug 04 '17 at 04:57
  • @BhatiManishKumar, changing your user ID to hide your name also rings alarm bells. It's not against this site's rules to ask homework questions, **as long as they are good questions.** You've had enough hints, now go learn some Python. – alexis Aug 04 '17 at 10:05

2 Answers2

1

If you don't need to do something special with regards to language processing, you don't need NLTK:

paragraph1 = paragraph1.lower().split()
paragraph2 = paragraph2.lower().split()

intersection = set(words1) & set(words2)
Geetha Ponnusamy
  • 497
  • 3
  • 15
  • 1
    @BhatiManishKumar The moment you start throwing unreasonable constraints that rings alarm bells - this is most likely homework or a project, otherwise there is no reason to install a 50MB library to do something that you could achieve with a simple set intersection. You aren't likely to find help here. – cs95 Aug 04 '17 at 04:23
  • 1
    @BhatiManishKumar, changing your user ID to hide your name also rings alarm bells. It's not against this site's rules to ask homework questions, **as long as they are good questions.** You've had enough hints, now go learn some Python. – alexis Aug 04 '17 at 10:05
0

You can use set.intersection.

p1 = '''
Electronic commerce, commonly written as E-Commerce, is the trading or  
facilitation of trading in goods or services using computer networks, such 
as the Internet or online social networks. Electronic commerce draws on 
technologies such as mobile commerce, electronic funds transfer, supply 
chain management, Internet marketing, online transaction processing, 
electronic data interchange (EDI), inventory management systems, and 
automated data collection systems.
'''.split()

p2 = '''
Modern electronic commerce typically uses the World Wide Web for at least 
one part of the transaction's life cycle although it may also use other 
technologies such as e-mail. The benefits of e-commerce include it’s the 
speed of access, a wider selection of goods and services, accessibility, and 
international reach.
'''.split()

print(set(p1).intersection(p2))
{'and', 'the', 'technologies', 'of', 'electronic', 'such', 'commerce', 'as', 'goods'}
umutto
  • 7,460
  • 4
  • 43
  • 53
  • thank you response but i want this in nltk. but also thank you – BMK007 Aug 04 '17 at 04:02
  • 1
    @BhatiManishKumar I'm not aware of any NLTK method to achieve the same result. If you check the [source](https://github.com/nltk/nltk/blob/8eb3803cb88a6e75d18d4f740678b218b3d8f4fd/nltk/text.py#L107) they also frequently use the set.intersection() to get similar results. – umutto Aug 04 '17 at 04:11