Skip to content

Instantly share code, notes, and snippets.

@JupyterJones
Created August 10, 2018 02:38
Show Gist options
  • Save JupyterJones/aff543bfe8c912007f3548f2f94429e0 to your computer and use it in GitHub Desktop.
Save JupyterJones/aff543bfe8c912007f3548f2f94429e0 to your computer and use it in GitHub Desktop.
Article summerizer
import warnings
warnings.filterwarnings('ignore', message='numpy.dtype size changed')
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize, sent_tokenize
from nltk.stem.snowball import SnowballStemmer
import nltk
text = """
as machines grow with artifificial intelligence abilities, and the fact that there \
is an almost unlimited supply of artistic examples available online, the machines \
abilities will soon become indesinguishable from that art created by living beings. \
in my opinion, the duties of a professor and lecturer on art ought to be, first, the \
general pilotage of the schools through the quicksands and mud-banks with which the \
deep-water channel leading to excellence is beset on every side; and, secondly, the \
alimentation of that subtle flame without which the architect degenerates into a builder, \
the sculptor into a statuary, and the painter into a handicraftsman. this choice of colors \
seems to have originated somewhere about the sixth century, but it was not till much later \
that the church adopted these colors so exclusively that the artist had no option in \
the matter. it has lasted even to the present day, and few painters of religious subjects \
for church decoration would venture upon a departure from thetime-honored red and blue. \
in the first place, these colors, when in combination, have come to have a kind of sacred \
significance, and from being reserved for the highest personages of the new testament, \
they serve the same purpose that was formerly fulfilled by the nimbus. again, they are \
strong primary colors; their juxtaposition in a picture is unusual, and therefore likely \
to draw attention to the figure which is clothed in them. it may be argued that as he personates \
the good shepherd, the artists of course give him a shepherds dress, but that this dress \
may have been totally unlike the one he actually wore. if, therefore, you have to paint \
any subject of the time of the kings, it would be incorrect to represent your personages \
with cropped hair and clean shaven. in the lectures i am about to deliver on early italian \
art, i shall notenter into minute detail, nor shall i attempt a history of all the painters \
of the fourteenth and fifteenth centuries who deserve mention. i shall, therefore, attempt \
nothing of the kind, and having always had a tender feeling for those whose attendance here \
is compulsory, and admiration for those who come of their own free will, i shall endeavor to \
be as little tedious as possible, whilst imparting to you a sort of resume of medival painting \
and the early italian schools. they vary in merit according to the skill of the artist who \
executed them, and also according to the epoch of their production, those of the second \
century being infinitely superior to those of the third and fourth. in the earliest of \
these paintings, the good shepherd replaces orpheus, elias replaces apollo, and so on, but \
the style is in no way distinguishable from contemporary roman wall-paintings. in the \
paintings of the third and fourth centuries there is a very noticeable decline in the drawing \
and execution, but there is still areminiscence of a classical style. indeed, so numerous \
are the little cupids and genii, and so prodigal has the artist been of vine tendrils, that \
the building containing it was formerly supposed to have been a temple of bacchus. they cannot \
certainly be called truly byzantine, although they have a decided byzantine flavor about them, \
and it is probable that many of them were executed by greek or byzantine artists; but, on the other \
hand, they are so strikingly dissimilar to late roman work that they ought to be classed in a school \
by themselves. the forms of thefigures are of course stiff and lifeless, if compared to the antique \
or to sixteenth-century art; but they are quite graceful and animated when compared with the dead \
ugliness of the real byzantine work. there is acertain grandeur, _sui generis_, about them particularly \
in the justinian and theodora mosaics of ravenna quite independent of their size and gorgeous \
ornamentation, which we never find in later byzantinework.
"""
stemmer = SnowballStemmer("english")
stopWords = set(stopwords.words("english"))
words = word_tokenize(text)
freqTable = dict()
for word in words:
word = word.lower()
if word in stopWords:
continue
word = stemmer.stem(word)
if word in freqTable:
freqTable[word] += 1
else:
freqTable[word] = 1
sentences = sent_tokenize(text)
sentenceValue = dict()
for sentence in sentences:
for word, freq in freqTable.items():
if word in sentence.lower():
if sentence in sentenceValue:
sentenceValue[sentence] += freq
else:
sentenceValue[sentence] = freq
sumValues = 0
for sentence in sentenceValue:
sumValues += sentenceValue[sentence]
# Average value of a sentence from original text
average = int(sumValues / len(sentenceValue))
summary = ''
for sentence in sentences:
if (sentence in sentenceValue) and (sentenceValue[sentence] > (1.1 * average)):
summary += " " + sentence
print(summary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment