#!/usr/bin/python3
# Encoding: utf8

# INPUT: trigrams 
# ARGUMENT: file with stopwords
# OUTPUT: trigrams in which stopwords and punctuation marks are replaced by the tag STOP 


import sys
import re
#import math
from collections import defaultdict

file_name = sys.argv[1]
file = open(file_name, 'r')

regex = r"[\.\,\;\:\«\»\'\"\&\%\+\=\$\#\(\)\<\>\!\¡\?\¿\\\[\]\{\}\|\^\*\-\€\/\_\·\¬\~]"

stop=[]
for token in file:
    token = token.strip()
    stop.append(token)
#    print >> sys.stderr,  token

for line in sys.stdin:
    line = line.strip() 
    line = line.split()
    if len(line) >= 3:
        w1 = line[0]
        w2 = line[1]
        w3 = line[2]

##check if the tokens are in the dictionary of stopwords
    if w1 in stop:
        w1 = "STOP"
    if w2 in stop:
        w2 = "STOP"
    if w3 in stop:
        w3 = "STOP"

##check if the tokens are punctuation marks
    if re.match(regex, w1):
        w1 = "STOP"
    if re.match(regex, w2):
        w2 = "STOP"
    if re.match(regex, w3):
        w3 = "STOP"

    print (w1, w2, w3)
