Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. parse a sentence [modified]

parse a sentence [modified]

Scheduled Pinned Locked Moved C#
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    farokhian
    wrote on last edited by
    #1

    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

    OriginalGriffO 1 Reply Last reply
    0
    • F farokhian

      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

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      F 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        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.

        F Offline
        F Offline
        farokhian
        wrote on last edited by
        #3

        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

        OriginalGriffO 1 Reply Last reply
        0
        • F farokhian

          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

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          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.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups