AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Compiling ChatScript under iOS
 
 

Hello everybody, I’m new to these forums. There is a ton of valuable information here and a great community. I’m looking forward to working with everyone here and making a contribution.

I am working on a bot that will be targeted for kids using iOS devices.

I have just started working with ChatScript today and I’ve never tried to get a C-based framework running under iOS. I played around with a couple of approaches today but haven’t gotten it to work so far. Could someone point me in the direction of steps to get ChatScript working inside an iOS Application or compiled as a framework?

Thanks for your help!

 

 
  [ # 1 ]

My browser’s auto-form-filler seems to have inadvertently created a poll out of this question. I don’t have access to remove the poll or delete the question. Could a moderator remove one or the other and I can repost if necessary. Thanks!

[edit]
I got your back, Chris! The poll has been removed, no worries! smile
[/edit]
Edited by Dave

 

 
  [ # 2 ]

I have good news and not so good news for you.

First- I’m not an iOS expert.  I know in abstract that if you create an XCODE project and list all the files of chatscript into it, it will probably compile. That still leaves you knowing how to access iOS to give you onscreen displays, etc.  I can’t help that area at all.

Second- There are limitations on iOS memory and a normal chatscript dictionary (full dictionary) is too big. There are various #define’s you can enable to discard parts of the engine code (like script compile, server, etc) but the dictionary is still an issue.

I can and do build mini-dictionaries (which is why Tom Loves Angela fits), but I don’t release the tools for manipulating the dictionary (part of my reserve abilities). This means you either have to manually remove entries from the full dictionary or write code to do it (it’s not trivial because entries cross reference each other and you will prefer that some wordnet ontology hiearchy survives to make things work better).  So if you want me to build you a mini-dictionary, that’s a private discussion and a noticable fee.  You can, however, presumably build your product using a full dictionary on a simulator until such time as you need to move onto a phone.

 

 
  [ # 3 ]

Thanks Bruce. That’s something to start with. I will continue working at it tomorrow and see if I can get it to compile.

That makes a lot of sense about the mini-dictionary. I will do some more code exploration and will more than likely speak to you privately about that at some point in the near future.

 

 
  [ # 4 ]

Thanks, Dave, for removing that poll.

I’ve been making some progress on this and have been able to get it to compile and also have a basic understanding of the flow of the ChatScript now. Here’s an update on the steps I’ve taken.

1: Create a new iOS project. Create a new “ChatScript” folder. Copy src, DICT, USERS folders and authorizedIP.txt into the ChatScript folder.

2: In Build Settings: Under “Apple LLVM compiler 4.0 - Warning Policies” - Change Inhibit All Warnings to “Yes”

3: In mainSystem.cpp:
Change:
int main(int argc, char * argv[])
To:
int ChatScriptMain(int argc, char * argv[])
To avoid a conflict with two main functions (iOS apps have their own main and that is what needs to be used).

The next step is providing an interface for actually hooking into ChatScript and allowing input and interaction. It looks like I will need to essentially simulate what MainLoop is doing but adjust the input and output buffers to use iOS interface elements. This doesn’t look like too big of a challenge, so I hope that’s all the internals that will need adjustment, but we’ll see. I’ll post another update when I make some more progress.

 

 
  [ # 5 ]

Thanks Dave. I guess the student still has plenty to learn from the master. I couldn’t see a way to do it.

It seems like you are on top of things here, so I now hand the moderating reins back to your good self.

 

 
  [ # 6 ]

The nominal external control over chatscript would be:

1. comment out main()
2.  from YOUR code do
 
// init chatscript
InitSystem(argCount,args,filepath,filepath);
InitStandalone();

// begin conversation
    PerformChat(“user”,”“,”“,NULL,output); 

// continue conversation
          PerformChat(“user”,computerID,input,NULL,output);

 

 
  [ # 7 ]

You will want the LIVEDATA folder moved over.
You only need src/dictionarySystem.h but you are welcome to copy over the entire folder.

You will want a place to “build” your bot. If this is all being done in your ios simulator, you will need a RAWDATA folder and TMP folder.

 

 
  [ # 8 ]

Been hacking at it all day, and made some more progress. For some reason I didn’t get email notifications about your posts Bruce, but I just saw them now when checking the board as I’m wrapping up for today.

The good news is that I did proceed on my own with almost all the same steps you mentioned, including the Init steps and PerformChat steps. I just got to the point where I had a complaint about LIVEDATA and moved it over. So that gives me a lot of confidence that my understanding of the codebase so far is accurate.

I am having some issues that seem to be mostly with pointer/memory referencing that I’m trying to figure out the cause of. Therefore, I’m still not getting valid responses, but the ChatScript code is definitely executing for the most part (except where I’ve commented temporarily to avoid the runtime pointer issues).

There were a few more steps/changes I needed to take to get code to execute at all with the XCode compiler in an iOS project. I’ll write them up when I have something that is giving valid responses and I consider the code structure a bit more.

As far as building the bot - I might do that via command line outside of iOS/XCode and copy the built bot manually, but I’ll cross that bridge a little later once I get the ChatScript running well.

 

 
  [ # 9 ]

I’m not sure what you mean by “You only need src/dictionarySystem.h but you are welcome to copy over the entire folder.”

I have the whole src folder in the project at the moment, so I can call functions in mainSystem.cpp. I don’t see a way around that, unless I have some kind of linked static library instead.

Am I missing something?

 

 
  [ # 10 ]

No. I wasn’t thinking of your compilation environment. Only of your execution of a compiled version environment.

 

 
  [ # 11 ]

Just a little update - I improved the architecture of the Objective-C (iOS) to C++ bridge using an Objective-C++ wrapper method that is working nicely. I also had to workaround some file pathing issues because XCode flattens the file structure during compilation. There were a few other modifications I made to take care of some minor issues.

I’ve been stuck for a number of hours now with some strange memory issues with the various topic*Map[] variables in topicSystem.cpp when executing LoadTopicData for script1.txt. I get EXC_BAD_ACCESS errors for some of the lines where it tries to modify the variable by reference in ReadInt or ReadInt64 and also when running AllocateString for the maps and memset functions further down.

I can comment past the error areas and it will push past it, but the topics aren’t loaded so no real conversation is occurring. Here is part of the debug output I currently get when the topic loading problems are commented out:

in script1.txt at 2: TOPIC: ~control 25 15415944383628213037 4 2 0 1252
  failed to read all of topic ~control read: 4369 wanted: 181429
Build1: words=6 facts=15 dtext=112 stext=181432

So far, I haven’t been able to figure this one out, maybe I’ll figure it out tomorrow, but I won’t be working the full day.

 

 
  [ # 12 ]

could you be running out of memory and it just didnt allocate some of the tables?

 

 
  [ # 13 ]

I’m running under the simulator at this point, so I should have a lot of memory to work with and I don’t think that’s the reason. But it’s a good thought and something I hadn’t thought much about. I’ll see if I can figure out a way to know for sure if that’s the case.

If all else fails, there is a tool called valgrind I can use to get more insight into the memory. The error I’m getting is often from a dereference/unallocated memory area and valgrind should help pinpoint those. I’m going to try that out either Monday or Tuesday and see if that gets me somewhere.

 

 
  [ # 14 ]

Since I have never encountered errors here, I’m not much use. What I would do would be to use gdb to walk past each line in loadtopicdata and see where values and data go wrong.  (Of course lucky me gets to do it under VisualC++ so it’s trivial to do- I have great pain doing this sort of thing under gdb in command mode)

 

 
  [ # 15 ]

I finally got past the Topic issues. It turned out that the script0.txt and script1.txt files weren’t opening properly for reading in InitTopicMemory() because of changes I had made to fix iOS pathing issues.

I haven’t changed all the file paths - especially the ones that write, but I have tried to change all the ones I can see that read data along the flow of the application.

So far I’ve been changing individual lines, which has been a bit of a hassle and isn’t good long term. I think I will have to try a different approach and modify the Fopen* functions to properly handle the pathing problem in IOS without changing the rest of the codebase, perhaps with use of #ifdef IOS. However, there are quite a few raw fopen() calls also which may be problematic.

So the system still isn’t conversing yet, but it is looking a lot better. Some of the numbers match up to what happens when I run it on the command line, but the words count is definitely quite a bit off and many others are off as well. I think once I get all the file system issues nailed down it will work.

For what it’s worth, this is the console output at the moment when I run it in the simulator:

ChatScript Version 2.9 32 bit
  Full dictionary code.
:  words=182,709 specials=307 waste=3978 hash=65536 avgseek=1.5 maxseek=13 facts=32,475 dtext=10684656
Keyword0 altered ~animal_homes
Build0: words=61587 facts=117146 dtext=1092168 stext=0
Build1: words=8 facts=15 dtext=500 stext=4460
Bad control word INCLUDE rule: 0 comment: # prep /conjunc before noun-gerund will be one of those instead of anything else - “I remembered to eat *after walking home”
Livedata: entries=10682 facts=918 dtext=131120 posrules=0
Used 42MB: dict 259,277 (23853kb) fact 150,554 (6022kb) text 11913kb buffer (12x80000= 960kb) user (1x7000= 7kb)
Free 44MB: dict 789,298 fact 649,446 text 18,086KB

Command Line version:

ChatScript Version 2.9 64 bit
  Server disabled.  Full dictionary code.
: Aug 18 09:07:58 2012 words=52,168 specials=2261 waste=28465 hash=65536 avgseek=1.1 maxseek=7 facts=32,475 dtext=3961052
Keyword0 altered Micronesian
Build0: words=59188 facts=116931 dtext=1042044 stext=0
Build1: words=5 facts=15 dtext=460 stext=4460
Currently have a substitute for jewellery in jewellery jewelry => jewellery
Livedata: entries=11887 facts=919 dtext=204956 posrules=485
Used 30MB: dict 153,980 (18477kb) fact 150,340 (6013kb) text 5213kb buffer (12x80000= 960kb) user (1x7000= 7kb)
Free 50MB: dict 894,595 fact 649,660 text 24,786KB

 

 1 2 > 
1 of 2
 
  login or register to react