-1
def Interpretation_is(sentence):
    print(sentence.split())
    print(sentence.split()[0])

    there = 'distant place'
    he = 'gender identity'

    if 'place' in setence.split()[0]:
        print(sentence.replace('is','exists'))
    if 'identity' in sentence.split()[0]:
        print(sentence.replace('is','equal to'))

Interpretation_is('there is a woman')
Interpretation_is('he is a boy')

Above Code rephrase the given sentence specifically regarding the meaning of 'is'

Since is only take care of its prior word, subject, I only take the sentence.split()[0] and evaluate its meaning again.

Question is, if I take sentence.split()[0], I eventually get 'there' as a string, but once again I want to let python reads it as a variable which consist of another tuple or set of strings, such as there = 'distant place or location' and check its whether there exists string 'place or location' in it.

Additional Question 1) In an advanced way, I want make up some word group which falls into the group of so called place, such as place = {there, here} then let the program check whether sentence.split()[0] actually falls in this group.

How could I do this?

Additional Question 2) When I refer a word with its meaning, such as is = {exist, parity}. If I note it following mathematical notation, there's no 'order' given, however if I make it as a list or tuple, such as is = (exist, parity) or is = [exist, parity] there inevitably 'order' is given.

Which data structure in python doesn't hold the 'order' in it?

Any recommendation or reference that I can check?

khelwood
  • 55,782
  • 14
  • 81
  • 108
Daschin
  • 119
  • 1
  • 4
  • you probably want to look into using Python's [dictionary](https://docs.python.org/2/tutorial/datastructures.html#dictionaries) structure, though I'm not entirely clear on what your desired output it. – asongtoruin Jul 19 '17 at 13:22
  • I am thinking of making rephraser of given sentence. @asongtoruin hope you see my answer – Daschin Jul 19 '17 at 13:23

2 Answers2

0
def Interpretation_is(sentence):
     print(sentence.split())
     print(sentence.split()[0])

     place = ('there', 'here')
     gender_identity = ('he', 'she')

     if sentence.split()[0] in place:
          print(sentence.replace('is','exists'))
     if sentence.split()[0] in gender_identity:
          print(sentence.replace('is','equal to'))

Interpretation_is('there is a woman')
Interpretation_is('he is a boy')
Daschin
  • 119
  • 1
  • 4
0

You get 'there' as a string because you split the string (sentence) into a list of strings.

What you are looking for is converting a string to a variable, which you can find answer here To convert string to variable name

Q2: In that case, you want to create a dict using the first string as the key, and create a tuple of the rest of the sentence (string) and use it as value.

string = 'there is a boy'
l = string.split()
d = {l[0]: tuple(l[1:])}
Chen A.
  • 10,140
  • 3
  • 42
  • 61