How to parse text to cdt values

Hi All,

I have a text where user will be giving the information in text format , any ideas hot to parse that data to cdt ?? 

Like usermight say , I am bhargavi from India .. from this need to extract as name : bhargavi , country : india something like this .

Thanks,

Bhargavi P.

  Discussion posts and replies are publicly visible

  • Would user be entering data in specific format? And is it not possible to have separate input components to collect such type of date?

  • Unless the text is in a structured form where you can guarantee a value by either its absolute position (e.g. characters 1 thru 30 represent 'Country); or the text is delimited using, for example, commas (e.g. "India,bhargavi,... ") where we know the text before the first comma is the Country, the second is name etc; or the text contains name:value pairs e.g. "Country: India, Name: bhargavi" then parsing text is going to impossible using conventional methods.

    Assuming your text IS structured in one of the ones above, you can use different methods to extract the values you want, and then you an use Appian's type! constructor to generate your CDT.

    So, as a worked example, you can use the function split() to separate out a comma-separated string of text into its constituent parts. The the type!constructor to create a CDT instance, referencing the relevant entry in the array of text that the split() function has generated.

  • Hi

    This is similar to implementing AI and AI is all about eliminating unlike choices. Having said that and referring to what mentioned, I have drafted this sample code. This is not the ideal way to implement this but is certainly one of the closest ways to get there. Hopefully, it gives you an idea in sort of which direction to go for.

     

    with(
      local!countries: {"India", "UK","USA"},
    
      local!userText_words:split(ri!userTxt, " "),
      local!articles: {"a", "an", "the"},
      local!prepositions: {"of","from","on","in", "to", "within","with","at"},
      local!places: index(local!userText_words, wherecontains(local!countries,local!userText_words),{}),
      local!pronouns: {"I", "We", "She", "He", "They", "him", "her", "their", "his"},
      local!verbs: {"am","is","are"},
    
      local!names: difference(local!userText_words,{local!pronouns,local!prepositions,local!countries,
      local!articles, local!verbs}),
      local!cdt: 'type!{urn:com:appian:types}candidatureDetails'(),
      a!sectionLayout(
        label:"",
        contents: {
          a!textField(
            label:"Enter text",
            value: ri!userTxt,
            saveInto:ri!userTxt
          ),
          
          a!columnsLayout(
            columns:{
              a!columnLayout(
                contents: {
                  a!checkboxField(
                    label:"Names",
                    choiceLabels: local!names,
                    choiceValues: local!names,
                    value:local!cdt.name,
                    saveInto:local!cdt.name,
                    showWhen: not(rule!APN_isEmpty(local!names))
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!checkboxField(
                    label:"Countries",
                    choiceLabels: local!places,
                    choiceValues: local!places,
                    value:local!cdt.communicationAddress,
                    saveInto:local!cdt.communicationAddress,
                    showWhen: not(rule!APN_isEmpty(local!places))
                  )
                }
              )
            },
            showWhen: not(rule!APN_isEmpty(ri!userTxt))
          )
        }
      )
    )