Skip to content

Instantly share code, notes, and snippets.

View richashworth's full-sized avatar

Richard Ashworth richashworth

View GitHub Profile
@startgantt
<style>
ganttDiagram {
task {
FontName Helvetica
FontColor black
FontSize 12
FontStyle
BackGroundColor GreenYellow
const MILLIS_PER_DAY = 1000*60*60*24
const HEADER_ROWS = 1
function hide() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const sheet = ss.getSheets()[0]
const dateCol = sheet.getRange("A:A").getValues().map(function(row) {
return row[0]
})
pos_adjs = ', '.join(get_related_adjectives("climate change", nlp(positive_phrase)))
neg_adjs = ', '.join(get_related_adjectives("climate change", nlp(negative_phrase)))
pos_row = [positive_phrase, pos_adjs, TextBlob(pos_adjs).sentiment[0]]
neg_row = [negative_phrase, neg_adjs, TextBlob(neg_adjs).sentiment[0]]
HTML(DataFrame([pos_row, neg_row], columns=["Text", "Relevant_Adjectives", "Relevant_Sentiment"]).to_html(index=False)
climate_change_forms = ["The facts about climate change",
"Changes in our climate",
"The climate is changing rapidly",
"Because the climate has changed,"]
df = DataFrame(climate_change_forms, columns=["Text"])
df['Lemmas'] = list(map(lambda x: ' '.join(list(map(lambda y: y.lemma_, nlp(x)))), climate_change_forms))
HTML(df.to_html(index=False))
positive_phrase = "It's great that people are talking about climate change"
negative_phrase = "Rapid climate change is bad for the environment"
for x in [positive_phrase, negative_phrase]: spacy.displacy.render(nlp(x), jupyter=True)
from textblob import TextBlob
positive_phrase = TextBlob("It's great that people are talking about climate change")
positive_phrase.sentiment_assessments
@richashworth
richashworth / spacy-tokenisation-example.py
Last active September 9, 2021 18:24
Tokenisation Example
text = " ".join(list(jonathan_ross_segments))
sentences = nlp(text).sents
HTML(DataFrame(map(lambda x: str(x), sentences), columns=["Sentences"]).to_html(index=False)
@richashworth
richashworth / ner-spacy-example.py
Last active September 9, 2021 18:01
NER example
text = "We can speak to the UK's own Greta Thunberg, because Amy Bray is a climate change activist from Cumbria, who is getting great acclaim for saying young people should be very worried about their future."
spacy.displacy.render(nlp(text), style="ent", jupyter=True)