-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountScript.py
More file actions
62 lines (55 loc) · 1.99 KB
/
countScript.py
File metadata and controls
62 lines (55 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from os import getenv
import pymssql
import csv
import spacy
import re
import sys
import numpy
import os
from spacy import en
from operator import itemgetter
from collections import Counter
import textCleanUp
import agent_sort
import spacyStopWords
import fileFunctions
import sqlQueries
import inputManagment
import temporalAnalysis
import config
#function to process all tweets split in datasets by keywords and by location
nlp = spacy.load("en")
server = 'localhost'
spacyStopWords.stopWordsList(nlp)
def connect():
conn = sqlQueries.connectionToDatabaseTest()
cursor = conn.cursor()
filterKeywords= fileFunctions.readKeywordFile()
#initiating a list for a total count statistics file
listOfKeywords = [("keyword", "Scotland")]
locationSc = "Scotland"
locationEn = "England"
searchQuery = config.searchStringForSqlQuery()
for word in filterKeywords:
print ("Search for '"+word+"' for all locations in the database has begun.")
#searching and collecting from database all words with that keyword in two datasets by location
if "+" in word:
wordList = word.split("+")
print (wordList)
resultSc=inputManagment.searchForGroup(cursor, wordList,searchQuery,locationSc)
#resultEn=inputManagment.searchForGroup(cursor, wordList,searchQuery,locationEn)
else:
resultSc = inputManagment.searchForKeyword(cursor, word,searchQuery,locationSc)
#resultEn = inputManagment.searchForKeyword(cursor, word,searchQuery,locationEn)
#countEn = len(resultEn)
countSc = len(resultSc)
#count = countEn+countSc
print ("Search for '"+word+"' has finished. There were "+str(countSc)+" tweets containing '"+word+"' in the database." )
print (" ")
wordTuple = (word, countSc)
listOfKeywords.append(wordTuple)
print("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+")
fileNameString = "keywordCount"
fileFunctions.writeCsvFile(listOfKeywords, fileNameString)
return
connect()