def parse_synonyms(text):
 errors = []
 synonyms = set()
 for (i, line) in enumerate(text.split('\n'), 1):
  line = line.strip()
  if (not line):
   continue
  count = line.count('=>')
  if (count < 1):
   errors.append(('Syntax error on line %d: No => found.' % i))
  elif (count > 1):
   errors.append(('Syntax error on line %d: Too many => found.' % i))
  else:
   (from_words, to_words) = [s.strip() for s in line.split('=>')]
   synonyms.add((from_words, to_words))
 if errors:
  raise SynonymParseError(errors)
 else:
  return synonyms

def parse_synonyms ( text ) : errors = [ ] synonyms = set ( ) for ( i , line ) in enumerate ( text . split ( '\n' ) , 1 ) : line = line . strip ( ) if ( not line ) : continue count = line . count ( '=>' ) if ( count < 1 ) : errors . append ( ( 'Syntax error on line %d: No => found.' % i ) ) elif ( count > 1 ) : errors . append ( ( 'Syntax error on line %d: Too many => found.' % i ) ) else : ( from_words , to_words ) = [ s . strip ( ) for s in line . split ( '=>' ) ] synonyms . add ( ( from_words , to_words ) ) if errors : raise SynonymParseError ( errors ) else : return synonyms
parse synonyms from user entered text .