├── Fact-Checker-Report.pdf ├── Problem_statement.pdf ├── README.md ├── script.py ├── sentences.py └── test.txt /Fact-Checker-Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SilentFlame/Fact-Checker/ff5382b44aa267301667488b9263ccc95120b48c/Fact-Checker-Report.pdf -------------------------------------------------------------------------------- /Problem_statement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SilentFlame/Fact-Checker/ff5382b44aa267301667488b9263ccc95120b48c/Problem_statement.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fact-Checker 2 | 3 | [![Join the chat at https://gitter.im/Fact-Checker/Lobby](https://badges.gitter.im/Fact-Checker/Lobby.svg)](https://gitter.im/Fact-Checker/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | A fact checker developed in Python. 6 | 7 | ### Pre-requisites ### 8 | 9 | - Should have sopex installed in your system. 10 | - For setting up sopex visit [sopex](https://github.com/codemaniac/sopex). 11 | - Now place the two files (script.py, test.txt) in the directory inside sopex directory. 12 | - script.py, test.py outside are just to show you what they are. 13 | - sentences.py is just an example how to separate sentences from a paragraph. 14 | - And you are good to go. 15 | 16 | ---------------------------- 17 | 18 | ### How to run ### 19 | - `$ cd sopex` 20 | - `$ python script.py` 21 | - Then you'll be provided all the sentences in the doc. 22 | - Prompt will ask for a fact which you have to enter like `"FACT"`. 23 | - You'll get provided with 3 outputs which signify 3 different things. 24 | - Similarity between `objects`. 25 | - Similarity between `predicates`. 26 | - True/False state of the fact. 27 | 28 | ----------------------------- 29 | 30 | #### other team members #### 31 | - [Ashutosh Ranjan](https://github.com/ranjan019) 32 | - Ayush Joshi 33 | 34 | -------------------- 35 | -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | import sopex 2 | import nltk 3 | from nltk import tokenize 4 | import sopex 5 | import nltk 6 | from nltk.corpus import wordnet 7 | fp = open("test.txt") 8 | data = fp.read() 9 | dd={} #Dictionary for handling negation cases 10 | sentences = tokenize.sent_tokenize(data) 11 | for x in xrange(len(sentences)): 12 | if sentences[x].find("not") !=-1: 13 | dd[sentences[x]]=1 14 | else: 15 | dd[sentences[x]]=0 16 | print sentences[x] 17 | 18 | 19 | triplets = [] 20 | for i in xrange(len(sentences)): 21 | p=sopex.extract(sentences[i]) # sopex.extractor.SOPTriplet object. where every object will have .object, .subject, .predicate attributes. 22 | triplets.append(p) 23 | 24 | p = input("Input a fact from the doc. please: ") 25 | target = sopex.extract(p) 26 | 27 | 28 | #print triplets[0].object 29 | #need t 30 | 31 | flag1 = -1 32 | flag2 = -1 33 | flag = 0 34 | for j in xrange(len(triplets)): 35 | #if triplets[j].object == target.object and triplets[j].predicate == target.predicate and triplets[j].subject == target.subject: 36 | w1 = wordnet.synsets(triplets[j].object)[0] 37 | w2 = wordnet.synsets(target.object)[0] 38 | w11 = wordnet.synsets(triplets[j].predicate)[0] 39 | w22 = wordnet.synsets(target.predicate)[0] 40 | print w1.wup_similarity(w2) 41 | print w11.wup_similarity(w22) 42 | if w1.wup_similarity(w2)>=0.5 and w11.wup_similarity(w22)>=0.5 and triplets[j].subject == target.subject: 43 | #sprint "aaya" 44 | flag1=1 45 | if p.find("not") !=-1: 46 | flag1=0 47 | if dd[sentences[j]] == 1: 48 | flag2=1 49 | if flag1==0 and flag2==1: 50 | flag=1 51 | break 52 | if dd[sentences[j]]!=1 and p.find("not") ==-1: 53 | flag=1 54 | break 55 | 56 | # here we can put an else if for the third part(OBJECT) as an antonym and put flag=2 to say that the fact is false or what? 57 | 58 | 59 | if flag==1 : 60 | print "The fact mentioned above is True." 61 | else: 62 | print "The fact mentioned above is False." 63 | 64 | 65 | -------------------------------------------------------------------------------- /sentences.py: -------------------------------------------------------------------------------- 1 | import nltk.data 2 | 3 | tokenizer = nltk.data.load('tokenizers/punkt/english.pickle') 4 | fp = open("test.txt") 5 | data = fp.read() 6 | print '\n-----\n'.join(tokenizer.tokenize(data)) -------------------------------------------------------------------------------- /test.txt: -------------------------------------------------------------------------------- 1 | India is a large country. The tree has a fruit. The tree has a root. Ram plays football. Ronaldo plays for India. Kohli is not a cricketer. India won the cup. Shyam is a friend. India rules the world. Library is made of books. Shyam runs in the field. Ram plays cricket. Delhi is the capital of India. Rohan does not play football. Ram and Shyam are good boys. 2 | --------------------------------------------------------------------------------