Friday, February 26, 2016

Tuesday, February 23, 2016

Artificial Intelligence - Scripting

I am still looking for a decent scripting language or at least a way to run code on-demand. The purpose is to create an AI that is capable of learning new abilities by calling existing functions. I do not want to create a function to display time. I want to be able to tell the AI to run Console.WriteLine(DateTime.Now.ToString()); which would result in the output of a time.

On a more advanced note, I would create specialized functions to add to the AI's capabilities. For example, create a function to determine if a shape is a triangle. I would then teach the AI that it has that feature and have it execute the function. This would be similar to humans learning to do functions already available to us like jumping to skipping to high jumping like any other complex actions.

But to have the AI start, there must be some basic functions that it needs to be capable of. There is definitely a need to replicate actions. Second, there needs to be a way for it to acknowledge that an action is positive or negative. Third, the AI cannot have the ability to do certain things like kill itself (i.e. delete itself), delete memory, etc.

Currently, the AI is still in its basic steps and still figuring out how to architect the process. The AI can only understand static commands and output pre-programmed responses. There is a second level of topic recognition so that a user can ask a two-stage question, although this is also pre-programmed and even more limited.

The next step is to have the AI access database information. This way it can at least have some basic manufacturing level AI status.


Reference

http://dlastlee.com/dAI/dAI.aspx

Tuesday, February 16, 2016

C# Partial Date Class

I have finally gotten around to creating a partial date class which can handle unknown date parts. The way that I managed this was by having a flag field to manage which parts of the date is unknown. Previously, I had separate fields for each part (i.e. day, month, and year). 

I find this method much easier to manage and cleaner to manipulate the different fields while having the same benefits of multiple fields (except for null values which was not important). On top of that, I only need two fields to manage instead of three fields and still have the flexibility to expand to include times if needed.

The first field is a date column. For unknown parts, any value will suffice. For example, if you knew someone started at the company 10 years ago, that person started in 2006. Without knowing the date and month, I just enter into the system 1/1/2006 (this can be 2/4/2006, 10/29/2006, etc.).

The second field is a flag field to let me know which parts of the date is unknown. I have designated that the column as a binary to minimize the size as I do not really need that many:
1 = day
2 = month
4 = year
8 = decade
16 = century
32 = millennium

If I do not know the day (for example someone's birthday is in March 2016), the date would be 3/1/2016 with a flag of 1. For the company start date example, the date would be 1/1/2006 with a flag of 3. 3 in binary would be 11 designated both day and month.

Unfortunately, I didn't think this completely through so the logic kind of changes for decade, century, and millennium. Here, I use these flags when year is 0 otherwise it overrides the remaining values because unknown year would also mean unknown decade, century, and millennium.

If I had time to redo the logic, the each flag could be used for each digit of the year. For example:
4 = 201X
8 = 20X6
16 = 2X16
32 = X016

The reason I think this is cleaner is because I would have all the flexibility to manipulate the year without losing any benefits of the current method. I have not switched because the flexibility is not great enough for me to update all the data and code because data degradation is consistent from smaller value to larger value. In other words, if the month is unknown, the day is also unknown. It is rare that the day is known without the month. It can happen but I have not had a need for partial years.

Most importantly for the class is the ToString() function. This saves me a lot of time of having to display partial dates. Currently, I just display the missing date as ?? (ie. 02/??/2016, 02/16/????, ??/??/2016, etc.). This could be expanded with more date formats.

Metadata file '....dll' could not be found - Mismatched .NET Version After Adding New Project

I added a new project to my solution and suddenly I get this error:
Metadata file '....dll' could not be found

I spent a few hours troubleshooting this error and was about to pull my hair out when I decided to look at the output tab. This provided more details than just the error above which basically was because my new project was on a newer version of .NET (4.5.2) while the rest of my projects were on (4.5).

To fix this, I just had to go into the project properties and change all the versions (decided to go to 4.6). Voila, simple fix... then I just wanted to bang my head against the wall.

I followed all the steps found searching on google but none of those solutions worked. Those suggested to remove/add references, manual build, clean/rebuild builds, etc. I eventually narrowed it down that it was definitely the new project, but the solution builds if no references point to it. The instant I have a reference even when not using anything in the new project will throw the error.

In conclusion, go to the Output tab to get more details on what the actual issue is.

Sunday, February 7, 2016

ASP.NET Web Services (first impression)

Implementing Microsft Web Services took a lot longer than I expected.  I was determined to use .NET's ScriptManager to implement the web service because I have already done custom javascript with JSON to pull from web services before.

Most frustratingly, I got stuck on the javascript code calling the webservice. Simply, I didn't realize the function takes in one more parameter than the web service requires. For example, I created a webservice "RepeatResponse(string UserInput)" which would mean that the javascript code would be "[namespace].[class].RepeatResponse("blah blah", [functionName]);" where functionName is a javascript function that will run when the web service responds.

For whatever reason, I did not think about it until I almost gave up and started to remove the javascript for ASP.NET's ScriptManager. While considering the pseudo-code in my head, I realized that I needed to execute a function when the web service responds which caused the light bulb to go off.

The other difficulty is troubleshooting the issue. Although I can break within the javascript, there is no error when the function is called. The only response I received was null.

Overall, there were a few other hiccups in fixing the setup of web services in Visual Studio. So far, I think it may have actually been easier to just use a simple JSON function to execute the web service. I have not found any strong evidence of using ScriptManager over regular JSON.


Note:
To implement ScriptManager, web.config also needs to be updated to include the ScriptHandlerFactory.
<system.webServer>
      <handlers>
        <add name="ScriptHandlerFactory" path="*.asmx" verb="*"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
             modules="ManagedPipelineHandler"
             scriptProcessor=""
             resourceType="Unspecified"
             requireAccess="Script"
             allowPathInfo="false"
             preCondition="integratedMode"
             responseBufferLimit="4194304"
             />      
      </handlers>
        <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>
Reference
https://msdn.microsoft.com/en-us/library/bb763183.aspx - Sample in link does not work