parse a sentence [modified]
-
Hi all I want to parse a sentence like:father(X,Y):-parant(X,Y),male(X).and some other sentences that the structure of these sentences are the same but they have variable length. I want to save each segment of these sentences in a Datatable. What is your idea about segmentation of these sentences?(I'm using text.Split, Do you have better suggestion?) If i use split methode i must use it in several times. Maybe you have better suggestion that i can use it easier?!
modified on Friday, January 22, 2010 3:14 AM
-
Hi all I want to parse a sentence like:father(X,Y):-parant(X,Y),male(X).and some other sentences that the structure of these sentences are the same but they have variable length. I want to save each segment of these sentences in a Datatable. What is your idea about segmentation of these sentences?(I'm using text.Split, Do you have better suggestion?) If i use split methode i must use it in several times. Maybe you have better suggestion that i can use it easier?!
modified on Friday, January 22, 2010 3:14 AM
Why have you got to use it several times? I assume it's because you need to break it differently depending on the delimiters - so you know it is X because it is preseeded by "(", followed by "," and the name is in front? If so, then why not use a Regex? Shouldn't be too complex if your sentances are all of the form A(B,C):-D(E,F),G(H) A Regex could split that into named groups pretty easily.
All those who believe in psycho kinesis, raise my hand.
-
Why have you got to use it several times? I assume it's because you need to break it differently depending on the delimiters - so you know it is X because it is preseeded by "(", followed by "," and the name is in front? If so, then why not use a Regex? Shouldn't be too complex if your sentances are all of the form A(B,C):-D(E,F),G(H) A Regex could split that into named groups pretty easily.
All those who believe in psycho kinesis, raise my hand.
Thx for your reply; I want parse this sentence and some other sentence like this to these segment: sentence : grandparant(X,Z):-parant(X,Y),parant(Y,Z). segment : father X Y parant X Y parant Y Z (variable X,Y,Z,.. must be upercase) what is the best way? Note:I think that if i want to use Regex , i must searh some particular expression but i want to parse any expression like above.
modified on Friday, January 22, 2010 4:59 AM
-
Thx for your reply; I want parse this sentence and some other sentence like this to these segment: sentence : grandparant(X,Z):-parant(X,Y),parant(Y,Z). segment : father X Y parant X Y parant Y Z (variable X,Y,Z,.. must be upercase) what is the best way? Note:I think that if i want to use Regex , i must searh some particular expression but i want to parse any expression like above.
modified on Friday, January 22, 2010 4:59 AM
A regex is probably the easy way:
(?<Parent>(?<PName>\w+)\((?<PX>.+),(?<PZ>.+)\)):-(?<Children>.*)
This does not do the complete job: It breaks it into "Parent" which consists of "PName" and "PX" and "PZ", and "Children" which is everything else. It is pretty simple to expand to break the children down as well, but I don't have the time to do everything for you! Get a copy of Expresso[^]which will help you understand what is going on - it's free and really works well. Then all you have to do is slide that into your C# and it should do the parse for you! After that, a bit of validation, and you are away.
All those who believe in psycho kinesis, raise my hand.