Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- liste = {"hallo" : "hello" ,"wie" : "how" ,"geht" : "how/well" ,"es" : "it" , "dir": "you"}
- def tokenize(sentence):
- tokens = []
- for word in sentence.split():
- if word[-1] in ".,!?;":
- tokens.extend([word[:-1], word[-1]])
- else:
- tokens.append(word)
- return tokens
- lang = liste
- def detect_pos(sentence):
- shorttoken= tokenize(sentence)
- for i in sentence:
- if lang in shorttoken:
- finden = shorttoken.index(liste.keys(0))
- if liste.values(shorttoken[finden]):
- return "hello"
- elif liste.values(shorttoken[finden +1]):
- return "how"
- else: return print("unkown")
- if __name__ == '__main__':
- detect_pos("hallo")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement