Advertisement
Guest User

PYTHON-GAENGET-2017

a guest
Feb 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. # steg 1: skapa lista med unika ord i träningsexempel
  2.  
  3. import string
  4.  
  5. workout_data = [('I love this car', 1),
  6.                 ('This view is amazing', 1),
  7.                 ('I feel great this morning', 1),
  8.                 ('I am so excited about the concert', 1),
  9.                 ('He is my best friend', 1),
  10.                 ('I do not like this car', 0),
  11.                 ('This view is horrible', 0),
  12.                 ('I feel tired this morning', 0),
  13.                 ('I am not looking forward to the concert', 0),
  14.                 ('He is my enemy', 0)]
  15.  
  16. word_list = []
  17. spec = string.punctuation+"1234567890"
  18.  
  19. # lägg till så att det tar bort de vanligaste funktionsorden? Ta sen 100 vanligaste orden
  20.  
  21. for words, b in workout_data:
  22.     words = words.split()
  23.     for i in words:
  24.         i = i.lower()
  25.         if i not in word_list:
  26.             word_list.append(i)
  27.  
  28.  
  29. # steg 2: för varje ord i sträng tilldela 1 om finns, 0 om noll
  30.  
  31. def encode_string(s):
  32.     # ta bort specialtecken ur s!!!
  33.    
  34.     x = s.split()
  35.    
  36.     # global res
  37.     res = []
  38.  
  39.     for word in word_list:
  40.         if word in x:
  41.             res.append(1)
  42.         # res.append(0)
  43.         elif word not in spec:
  44.             res.append(0)
  45.     return res
  46.  
  47. """
  48. def rensa(s):
  49.    e = ''
  50.    for tecken in s:
  51.        if tecken not in spec:
  52.            e += tecken
  53.    return e
  54. """
  55.  
  56. print(encode_string('love view hej'))
  57. y = []
  58. x = []
  59. # steg 3: översätt inputvektorer till x input
  60. # översätt positiv och negativ till y
  61. for a, b in workout_data:
  62.     for a in workout_data:
  63.         encode_string(a)
  64.     for b in workout_data:
  65.         if b == 1:
  66.             y.append(1)
  67.         else:
  68.             y.append(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement