AI Zone Admin Forum Add your forum

Chatbot Conference London On Oct 3th Erwin will be moderating on the Chatbots conference in London. Why don't you meet him there? As a visitor, you'll get a discount as well: Why don't we meet there? get a discount

We do experience some trouble with our forms and some details page. We'll fix this ASAP. Sorry for the inconvenience!
Reading words in a sentence and characters in a word


Can anybody Please tell me

How to read words from a sentence
Ex :-
      $a = The time is 12:00 // This is extracted from user input senstence like ( _* ) $a = _0
      now i want to loop each word in the sentence and compare if it is lies in a concept

      let $c = 12:45
      now i want to loop through each letter in the word
      I want to know if this word is in time format or something else


  [ # 1 ]

Normally you would not loop thru words. You would directly see if some concept is present.

u: ( _~myconcept)  do something with found word.  ^retry(RULE) —go see if more of concept are found

and if you try :prepare 12:45 you will see what concepts (like some kind of time)  that word is in

Not to say that one can’t loop thru words, only that you havent demonstrated a need yet


  [ # 2 ]

Making a concept with all valid Hours:Minutes:Seconds would be a concept with 43,200 members.  If we could split the time based on the “:” colon delimiter and then test for hours, minutes, seconds separately then we would only need 3 concepts.  If hours has numbers 0 to 12 plus zero padded strings 00-09 then minutes only needs 13 to 60 and seconds can be the same as hours.


concept: ~clockhours [ 1 2 3 4 5 6 7 8 9 00 01 02 03 04 05 06 07 08 09 10 11 12 ]
: ~clockminutes [ ~clockhours 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 ]
: ~clockseconds [ ~clockminutes ] 

I tried various ways to substitute a character in the middle of a “word”.  We need to add spaces around the colon.  So “12:12:12” needs to become “12 : 12 : 12”  I thought it should be possible in the systemessentials.txt file but could not get a character substitution to work.  I settled on this topic which I call from my control file but the rule can be combined with the topic below for testing.

topic: ~CustomSubstitutions system ()
: ( !$$SpacesAdded _* ) 
$NewInput = ^substitute(character '_0 : " : ")
 $$SpacesAdded = TRUE

Once the time segments are split by spaces and colons you can use the concepts in rules to catch valid and invalid combinations:

TOPIC: ~IsThisTime keep repeat is this time xxtime )

u: ( _~clockhours _~clockminutes _~clockseconds YepThis is a time with hoursminutes and secondsTime: ^join('_0 : '_1 '_2)

u: ( _~clockhours : _~clockminutes : _~number ) This looks like a time but is not a valid time. Time: ^join('
_0 '_1 : '_2)

u: ( _~clockhours _~number :  _~clockseconds This looks like a time but is not a valid timeTime: ^join('_0 : '_1 '_2)

u: ( _~number : _~clockminutes : _~clockseconds ) This looks like a time but is not a valid time. Time: ^join('
_0 '_1 : '_2)

u: ( _~clockhours _~clockminutes YepThis is a time with hours and minutesTime: ^join('_0 : '_1)

u: ( _~clockhours _~number This looks like a time but is not a valid timeTime: ^join('_0 : '_1)

u: ( _~number _~clockminutes This looks like a time but is not a valid timeTime: ^join('_0 : '_1)

u: ( _* ) This sentence does not seem to contain a valid time'_0 

Sample Output:
alaric: > is this a time 12:12:12
HARRY:  Yep. This is a time with hours, minutes and seconds. Time: 12:12:12
alaric: > is this a time 61:12:12
HARRY:  This looks like a time but is not a valid time. Time: 61:12:12
alaric: > is this a time 61:12
HARRY:  This looks like a time but is not a valid time. Time: 61:12
alaric: > is this a time 12:12
HARRY:  Yep. This is a time with hours and minutes. Time: 12:12
alaric: > Is this a time aa:aa:aa
HARRY:  This sentence does not seem to contain a valid time: is this a time aa :  aa : aa

The valid combinations could be combined into a patternmacro.  There are probably better ways to do this.  It might be better to see if a word started with a number and then use a more custom function to parse the time.  I tried:

u: ( _1* )

to try to match words that started with a one but that did not work.

I also tried:

u: ( _~clockhours* )

to try to match anything that started with clockhours and then we could use refine but wildcard matching on words starting with a concept does not seem to work.  There might be a javascript way to test for a time pattern.  It would be best to put the time segments back together again and ^mark the time as a ~time concept once we find a matching pattern.

Ideally we could use something like:

u: ( is _* a valid time ) ^refine()
    a: (~time) Yes.
    a: () No.


u: ( schedule my meeting from _~time to _~time )
    Ok.  Your meeting has been scheduled from _0 to _1.





  [ # 3 ]

I didnt say you needed to create such a concept. just as you don’t need to create the concept ~number that CS already supports.  There is ~actual_time.


  [ # 4 ]

Hi Himanshu

back to the subject (as general question);

if you want to process a sentence
- word-by-word,
- or char-by-char,

a possible way is to create a factset from your original sentence with cs system function ^burst

You can split the sentence by words or by chars and iterate the factsect ( sort of an array of items)

- as a list (in the example below I used method ^first() )
- or as a indexed array (in this case you can use the method ^nth() instead of first.

The example below show the useless (!) processing to substitute all vocal o with the uppercase O, in any chars of a sentence (a variable):

tenter one or more words
: (_*)
# avoid standard cs sentence processing
$_charsequence = ^original(_0)

# create a factset as an "array" of characters
@= ^burst($_charsequence "")

# iterate the word as a sequence of characters
$_len = ^length(@0)

# get next character
$_char = ^first(@0)

# process the character
      # useless case: do uppercase for character with value "o"
if ( $_char == { $_char O }

# join it in an output string
$_out = ^join$_out _ $_char )

   $_out \n 


>> giorgio Dalla Chiesa in Guido

  g i O r g i O   D a l l a   C h i e s a   i n   G u i d O


See System Function Manual:—factset-count-




  [ # 5 ]

The standard word-by-word idiom is

u: (_*1) .... ^retry(RULE)


  [ # 6 ]

Hi Everyone

Thanks for the comments.



  [ # 7 ]


Can we use
  @0 = ^burst($_charsequence ~colors)

I tried - it is not working.


  [ # 8 ]


burst takes a static string to use as the burst value,  a concept is not that


  [ # 9 ]

But—what are you trying to do?  what example do you have?


  login or register to react