Skip to content

Instantly share code, notes, and snippets.

import spacy
nlp = spacy.load('en_core_web_md')
nlp.get_pipe('attribute_ruler').add([[{"TEXT":"Angeltown"}]],{"LEMMA":"San Fransisco"})
doc = nlp(u'I am flying to Angeltown')
for token in doc:
print(token.text, token.lemma_)
import spacy
nlp = spacy.load('en_core_web_md')
doc = nlp('I joined WSP 2.5 years ago as a graduate engineer.')
for token in doc:
print(token.text, token.lemma_)
import spacy
nlp = spacy.load('en_core_web_md')
text = "let's go!"
doc = nlp(text)
tok_exp = nlp.tokenizer.explain(text)
for t in tok_exp:
print(t[1], '\t', t[0])
doc = nlp("gimme that book")
print([w.text for w in doc])
from spacy.symbols import ORTH
special_case = [{ORTH: "gim"}, {ORTH: "me"}]
nlp.tokenizer.add_special_case("gimme", special_case)
print([w.text for w in doc])
import spacy
nlp = spacy.load('en_core_web_md')
doc = nlp('I own a dell computer.')
print([token.text for token in doc])
@jabirjamal
jabirjamal / NLP-02_sentence_segmentation.py
Last active July 23, 2021 06:11
Sentence segmentation
import spacy
nlp = spacy.load("en_core_web_md")
text = "I flew to Melbourne yesterday. I was at my hotel at 5 pm."
doc = nlp(text)
for sent in doc.sents:
print("***")
print(sent.text)
@jabirjamal
jabirjamal / Radiation3.py
Created July 20, 2021 16:31
Radiation Calculator 3
import math
while True:
try:
f1b = float(input("Enter height of the emitting panel F1, F_1b: "))
f1a = float(input("Enter length of the emitting panel F1, F_1a: "))
f2b = float(input("Enter height of the emitting panel F2, F_2b: "))
f2a = float(input("Enter length of the emitting panel F2, F_2a: "))
f3b = float(input("Enter height of the emitting panel F3, F_3b: "))
@jabirjamal
jabirjamal / Radiation2.py
Created July 20, 2021 16:27
Radiation Calculator 2
import math
while True:
try:
b = float(input("Enter length of the emitting panel: "))
a = float(input("Enter width of the emitting panel: "))
c = float(input("Enter distance between the emitting panel and the plane element: "))
break
except:
print("Error! Enter a valid number")
@jabirjamal
jabirjamal / Radiation1.py
Created July 20, 2021 16:22
Radiation Calculator 1
import math
while True:
try:
b = float(input("Enter length of the emitting panel: "))
a = float(input("Enter width of the emitting panel: "))
c = float(input("Enter distance between the emitting panel and the plane element: "))
break
except:
print("Error! Enter a valid number")