In [47]:
# print("\x1b[30;1m\"red\"\x1b[0m")
# print("\x1b[31;1m\"red\"\x1b[0m")
# print("\x1b[32;1m\"red\"\x1b[0m")
# print("\x1b[33;1m\"red\"\x1b[0m")
# print("\x1b[34;1m\"red\"\x1b[0m")
# print("\x1b[35;1m\"red\"\x1b[0m")
# print("\x1b[36;1m\"red\"\x1b[0m")
# print("\x1b[37;1m\"red\"\x1b[0m")

# print("\x1b[30;1m\"red\"\x1b[0m")
# print("\x1b[31;1m\"red\"\x1b[0m")
# print("\x1b[32;1m\"red\"\x1b[0m")
# print("\x1b[33;1m\"red\"\x1b[0m")
# print("\x1b[34;1m\"red\"\x1b[0m")
# print("\x1b[35;1m\"red\"\x1b[0m")
# print("\x1b[36;1m\"red\"\x1b[0m")
# print("\x1b[37;1m\"red\"\x1b[0m")

# print("\x1b[30m\"red\"\x1b[0m")
# print("\x1b[31m\"red\"\x1b[0m")
# print("\x1b[32m\"red\"\x1b[0m")
# print("\x1b[33m\"red\"\x1b[0m")
# print("\x1b[34m\"red\"\x1b[0m")
# print("\x1b[35m\"red\"\x1b[0m")
# print("\x1b[36m\"red\"\x1b[0m")
# print("\x1b[37m\"red\"\x1b[0m")


"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
"red"
ESC[ … 38;5;<n> … m"red"

In [96]:
from __future__ import print_function
import regex as re

# for x in range(256):
# # #     formatting = "\x1b[" + str(x) + "m\"red\"\x1b[0m"
# # #     formatting = "\x1b[" + str(x) + "m k \x1b[0m"
#     formatting = "\033[38;5;" + str(x) + "mo \x1b[0m"

#     print(formatting, end=" ")
    
#     if x%36 == 15:
#         print("")


def print_this_way(string, x, y):
#     formatting = "\033[38;5;" + str(16 + int(4*x) + 36*int(4*y)) + "m\"red\"\x1b[0m"
    formatting = '\x1b[38;5;' + str(16 + int(4*x) + 36*int(4*y)) + 'm'+ string +'\x1b[0m'
#     print(formatting, end=" ")
    print('\x1b[38;5;' + str(16 + int(4*x) + 36*int(4*y)) + 'm'+ string +'\x1b[0m', end=" ")

import numpy as np

for x in np.arange(0,1,0.2):
    for y in np.arange(0,1,0.2):
        print_this_way("o", x, y)
    print("")


#     formatting_ = "\x1b[37m\"red\"\x1b[0m"
#     print(formatting_, end=" ")
    
#     print(type(formatting))
#     print(type("\x1b[37m\"red\"\x1b[0m"))
    
    
#     "\x1b[37m\"red\"\x1b[0m"


o o o o o 
o o o o o 
o o o o o 
o o o o o 
o o o o o 

In [15]:
print('\x1b[1;31m'+'Hello world'+'\x1b[0m' + " noobs")


Hello world noobs

In [3]:
import sys
from termcolor import colored, cprint

text = colored('Hello, World!', 'red', attrs=['reverse', 'blink'])
print(text)
cprint('Hello, World!', 'green', 'on_red')

print_red_on_cyan = lambda x: cprint(x, 'red', 'on_cyan')
print_red_on_cyan('Hello, World!')
print_red_on_cyan('Hello, Universe!')

for i in range(10):
    cprint(i, 'magenta', end=' ')

cprint("Attention!", 'red', attrs=['bold'], file=sys.stderr)


Hello, World!
Hello, World!
Hello, World!
Hello, Universe!
0 1 2 3 4 5 6 7 8 9 
Attention!

Insults package


In [1]:
from insults import Insults
Insults.load_model()

In [106]:
comment = "You eat people?"

In [107]:
Insults.rate_comment(comment)


Out[107]:
0.21483478528622635

In [108]:
comments = ["You called me a \"dickhead\", so I'll say you're a cunt.", "These shitakes taste like shit."]
print(Insults.foul_language(comments, context=False))


(['cunt', 'shit'], None)

Identifying quotation marks

https://regex101.com/r/cB0kB8/1 https://stackoverflow.com/questions/39713487/extracting-quotations-citations-with-nltk-not-regex

For now we only care about double inverted commas, and all text that is within a pair of double inverted commas is treated at quotation. If you include single inverted commas you need to deal with the issue of parsing the apstoshes (people's, it's). Perhaps cleanup can be done with nltk, for future work.

There is also a need to differentiate between inverted commas used for sacarsm and used for quotation. Moreover, some sites format quoted text in a different way (exited from the text and centred, with name at the bottom right) - and such quotation is not captured.


In [9]:
fake_news = u'''
Prime Minister Lee Hsien Loong has been addressed as a dictator by many Singaporeans and rightly so, but few can point out what he actually did that defines him as one – after all, everything is legal right? For a start, dictators write their own rules and never subject themselves to the rules they wrote. The one trait shared between Lee Hsien Loong and dictators like Kim Jong Un, Hitler, Stalin and Mao is when they are all above the laws, it is still legal. One just need to look at the joke of a Presidential Election conducted this year to understand what a dictator is all about:

Writing his own laws
Knowing that having a race-based election infringes the Constitution, Lee Hsien Loong single-handedly abused his majority power in Parliament to re-write the Constitution. After making a mistake about Halimah Yacob’s Indian race, Lee Hsien Loong appointed a committee of his cronies to re-write the definition of the Malay race.

Creating proxies to act on his behalf
The 16-member committee to decide “Malayness” was appointed by Lee Hsien Loong and the committee actively consults the dictator for directions. The Council of Presidential Advisers (CPA) restricting the powers of a President also acts by Lee Hsien Loong’s bidding. Halimah Yacob herself is a walking puppet and proxy of Lee Hsien Loong. These proxies are created to create a facade that due processes are in place, but a sharper mind knows better.

Breaching the laws he created
When opposition party’s ex-member Yaw Shin Long resigned from his MP position, a by-election was called and insisted so by Lee Hsien Loong. However, when Halimah Yacob resigned from her MP position, Lee Hsien Loong feigned ignorance and claimed no by-election is needed. However the fact remains that the Parliament lost one representative voice (not that it matters since it is still PAP anyway), so a by-election should be called for Yew Tee-Marsiling GRC.

Abuse laws to his political advantage
A walkover is legal, according to the election laws he written. Therefore, the Lee Hsien Loong-endorsed candidate becoming a President through a walkover is wholly legit. Banning the two opponent Presidential contestants because they fail to meet the S$500 million financial requirements is also perfectly legit. Halimah Yacob, an Indian, is now a legit Malay because a committee said so. Everything is legal yet corrupted, the colour white is actually a stain itself.

His words are final
Like all dictators, Lee Hsien Loong’s words are final. Yes there are unhappiness, he said, “but I did the right thing”. Lee Hsien Loong’s words exemplify the saying that the road to hell is paved with good intentions. A civil court case launched  by Dr Tan Cheng Bock was blocked by the High Court. Opposition MP Sylvia Lim’s question in Parliament is denied, twice. Nobody could ask a damn question, because his words are final. Gutter politics at it’s finest.

Whether Singapore is corrupted depends on one’s acceptance of the political system. If Singapore is perceived as a democracy, it breaches every value of the Singapore pledge and the government is corrupted inside out. Whereas if Singapore is perceived as a dictatorship, it is fully legitimised and corruption-free.
'''

We need to clean up the open and closed inverted commas with straight ones.

Or we can use the information of the open and closed inverted commas, but not all sites typeset as such.


In [16]:
import unidecode
fake_news_ = unidecode.unidecode(fake_news)

In [17]:
import regex as re

print(re.findall(r'"(.*?)"', fake_news_))


['Malayness', 'but I did the right thing']

Identify key words or convert statement into a fact-checking question.


In [18]:
#todo

In [ ]: