iit-cs585 / assignments

Assignments for IIT CS585
3 stars 7 forks source link

test_get_productions() #3

Closed qsong4 closed 7 years ago

qsong4 commented 7 years ago

Im still confuse about test function test_get_productions() self.assertEqual(productions[0], ('S', ['NP', 'VP'])) self.assertEqual(productions[1], ('NP', ['N'])) self.assertEqual(productions[2], ('N', ['John'])) self.assertEqual(productions[3], ('VP', ['V', 'N'])) self.assertEqual(productions[4], ('V', ['books'])) self.assertEqual(productions[5], ('N', ['flight'])) Depend on the test case we know that the left side of list is the top of stack, so we need to sort the list ['NP', 'VP'] then we can make 'NP' at the top of stack. But at this case self.assertEqual(productions[3], ('VP', ['V', 'N'])) 'V' is at left side of 'N', so I can not pass the test case. I think there is something wrong about test case. Hope I clearly express my situation...

qsong4 commented 7 years ago

Anyone pass the test case of this function, please help!

aronwc commented 7 years ago

@qsong4 Sorry, I don't quite understand your question.

The purpose of get_productions is to list the CFG rules that are used to produce the given tree. The order in which the rules are returned is depth-first, left-to-right.

For the example in the test case, the first rule is S->NP VP. Then, we expand the NP rule, since it is the left most constituent that has not been expanded. This leads to N -> John. There should not be a need to sort any of the right-hand-sides of any rule.

You may find recursion helpful for completing this function.

Hope that helps, Aron

qsong4 commented 7 years ago

@aronwc Because this tree structure does not have left and right, we can not control what on the left without sorting. For example, the first rule is S->VP NP without sorting, but after sorting the fourth rule become VP-> N V which does not satisfy the test case. Hope I make myself clear this time :)

I am gonna try recursion, maybe it will not have this problem.

qsong4 commented 7 years ago

Karthik Shivaram notifications@github.com于2017年1月22日 周日下午3:40写道:

Figured it out , implemented breadth first search by mistake.

Hi, could you tell me which way does you us to implement BFS, recursion or stack?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/iit-cs585/assignments/issues/3#issuecomment-274361886, or mute the thread https://github.com/notifications/unsubscribe-auth/APO98SBQkmS_HR5Ms3BKI0bRLI_SSd4Rks5rU8zLgaJpZM4Lo2Qe .

karthikshivaram24 commented 7 years ago

I had used a deque by mistake without noticing it was BFS logic, then i tried with a stack but still output would not match due to the order of the nodes entering the stack, hence i used recursion as Professor suggested , it is working now.

qsong4 commented 7 years ago

Karthik Shivaram notifications@github.com于2017年1月22日 周日下午7:37写道:

I had used a deque by mistake without noticing it was BFS logic, then i tried with a stack but still output would not match due to the order of the nodes entering the stack, hence i used recursion as Professor suggested , it is working now.

Thanks, I have same problem with stack, Im gonna try recursion.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/iit-cs585/assignments/issues/3#issuecomment-274378102, or mute the thread https://github.com/notifications/unsubscribe-auth/APO98WAmkdlED7uTY3dYLi1sXC-nEo2eks5rVAQ9gaJpZM4Lo2Qe .