-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractor.py
More file actions
69 lines (55 loc) · 1.59 KB
/
extractor.py
File metadata and controls
69 lines (55 loc) · 1.59 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
63
64
65
66
67
68
69
#! /usr/bin/python
# -*- coding: utf-8 -*-
'''
Extracts the content from a html file
'''
import html2text
import libGeneral
import re
import nltk
import codecs
def extract(s):
# Remove special characters
# Remove additional spaces
# Make string lower case
htmlContent = libGeneral.removeSpecialCharacters(s)
htmlContent = libGeneral.removeAdditionalSpaces(s)
htmlContent = libGeneral.makeStringLowerCase(s)
wordList = htmlContent.split()
# Remove single characters
# wordList = removeSingleCharacters(wordList)
return wordList
'''
Remove stopwords from a given string
'''
def removeStopwords(wordList, language):
inputFile = codecs.open("./stopwords/"+language+".txt", "r", "utf-8")
inputString = inputFile.read()
#inputString = libGeneral.removeSpecialCharacters(inputString)
inputString = libGeneral.removeAdditionalSpaces(inputString)
inputString = libGeneral.makeStringLowerCase(inputString)
stopwordList = inputString.split()
x = len(wordList) - 1
while x > -1:
word = wordList[x]
if word in stopwordList:
del wordList[x]
x -= 1
return wordList
'''
stems the given list of words
'''
def stemList(wordList):
stemmer = nltk.stem.porter.PorterStemmer()
outputList = []
for word in wordList:
outputList.append(stemmer.stem(word))
return outputList
'''
Removes single characters from a given list
'''
def removeSingleCharacters(wordList):
for word in wordList:
if len(word) == 1:
wordList.remove(word)
return wordList