Chat with me

Go Back

Logging your expenses using Oslo SDK!

I had the privilege of speaking at the Microsoft Innovation Day. Unfortunately it was a small session that cannot fit to even go very quickly on everything on Oslo.

 

We're going to get started with a small real life scenario as an example: I really want log my daily expenses as I go. I don't want to wait till I go home to start adding those expenses & trying to remember them.

 

So What we'll do is pretty simple, we're going to record some data like "I spent $10 on food" at my mobile, send it through SMS , email it then i have the same processor on the other end to "understand" and save it to a database.

 

What's DSL ?

DSL or Domain Specific Language means as you read it. It is some sort of language for a specific domain , could be music, medicine, economy or even a system analysis language.

 

Just before we get started, this is a pretty simple demo that was made specifically for short presentations, it would give you a sneak peak about what Oslo is, but this is like 10% of what Oslo does, so have a look at the resources paragraph at the end.

 

1. Download Oslo SDK

You can download January 09 CTP from here.

 

2. Add your Domain Specific Language Text

1

3. Open a template.

a. Create a new file and name it Expenses.mg.

b. Press CTRL+ALT+T to open the template pick window & open the Expenses.mg file.

c. The Window turns to a 3 panes mode.

asd

4. Start Building MGrammar

a. Everything should start with a module

b. Inside the module we can define a new language, import other languages, create queries & relations & lots of stuff I'll talk about on other posts.

c. We'll start by defining the module & naming the Language. Languages always start with syntax Main syntax

sdf 

d. Now I am telling the computer that my "Expenses Language" consists entirely of only one sentence "I spent 400 LE on Taxi". The computer understands it & displays on the preview pane what it understood.

5. "Tokenize" the syntax

a. We'll start tokenizing the syntax, so we can extract the useful information from the raw data.

b. We'll ignore the whitespaces for now , interleave keyword instructing the parser to ignore those characters/syntax. We'll ignore spaces, dots , Carriage & Line Feeds.

5

6. Generalizing the tokenized text

a. If i tried to replace "400" with "300" it won't work. So we need to generalize the variable data. We'll create "tokens" that represent the data we want so we can accept variables.

6

 

7. Project extracted information to "data stores"

a. After Extracting the data , we'll project these data to data stores. Data stores is just a name came by my mind to simplify the concept of Projection is "redirecting" or "reformatting" these data to a whole new schema that would be used to generate the M file.

b. I meant to change the names of the projected value to show you the difference (i.e. Person -> Name, Amount -> Money, etc...)

7

8. Accept multiple entries

a. Now, It's not practical to insert only one item each time , I want to say I spent X on this & Y on that at the same time. Here's how can we can we accept multiple entries and how to project them.

8

 

9. Running M commands

Save the files, I save the DSL pane contents as "expenses.dsl".

 

The commands you can find at "C:\Program Files\Microsoft Oslo SDK 1.0\Bin" I always add that path to the Environment Variable %PATH%. We'll use four commands that takes the dsl input file and saves it to a SQL database as the following:

 

    Compile the Model using MG Tool. It generates a expenses.mgx file at the same directory
    mg expenses.mg

    Use the Language Utility to Generate M File by referencing the generated mgx file from the previous step. This step generates a expenses.m file.
    mgx  expenses.dsl /r:expenses.mgx 

    Compile the M generated file to an Image using M utility.
    m expenses.m /p:image

 

    Load the Compile File to the database... (Use /c to create a new DB & /s if you are not using the default SQL instance)
    mx /i:expenses.mx /d:NEW_DB /s:(local)\MY_SQL_INSTANCE /c

 

10. Check the extracted information in the database

Open your SQL Server, you'll find the database crated (I used demo db instead of NEW_DB db)

10

 

So you can now run reporting, use excel data feature, do whatever you want on expenses we just wrote on a regular file.

 

Here's the final grammar file:

module Finance
{
    language Expenses
    {
        syntax Main = s:Spending* //* means a collection of Spendings
            //valuesof keyword projects multiple values from a collection
            => Spendings {valuesof(s)};
        syntax Spending = p:Person "spent" a:Amount c:Currency "on" i:Item
            => {Name = p, Money = a, Currency = c , Description = i};

        //Read Characters from A to Z Case Insensitive
        token Person = ('a'..'z' | 'A'..'Z')+;
        //Accept only numbers from 0 to 9
        token Amount = ('0'..'9')+;
        token Currency = ('a'..'z' | 'A'..'Z')+;
        token Item = ('a'..'z' | 'A'..'Z')+;
        //Eliminate the white spaces & trivial characters
        interleave Whitespaces = ' ' | '\r' | '\n' | '.';
    }
}

 

Please contact me at remon.zakaria { a t } dashsoft.com if you need more information.

Facebook DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Furl it!

Comments  12

  • Said Fawzy 25 Apr, 11:28 AM

    It was short Demo yes
    But it was great really .. you did well Remon
    I really need it to read it again  really
    It seems that you have read my mind ,so you recorded it here
    I will try to download the SDK and try it and tell you what I think
    Thank you again
  • Ahmed Nady 25 Apr, 02:48 PM

    Thanks Remon for this good information
  • Remon Zakaria 28 Apr, 10:52 PM

    You're welcome guys. If you need guidelines on how to start with Oslo , let me know please.
  • Norwegia 14 Nov, 08:09 AM

    Yet another article on the Badrkhan sisters from Norway. These sisters are designing headscarves for the muslim women of Norway. Now they want to go international. The sisters have already held five fashion shows in Norway this year, and aims on having an exibition at the Islamic Expo in London next year.
  • Maisyn 22 Jun, 01:27 AM

    Good point. I hadn't thugoht about it quite that way. :)
  • Elida 22 Jun, 02:27 PM

    All of my questions setteld—thanks!
  • jccesqdzq 23 Jun, 05:47 AM

    Z0J8X7 , [url=http://gwsagwhnfknl.com/]gwsagwhnfknl[/url], [link=http://liuomsrjlhji.com/]liuomsrjlhji[/link], http://xrjcojcwfmvh.com/
  • bwcqqe 23 Jun, 07:58 AM

    ZM6OCr , [url=http://evdgqodftxlb.com/]evdgqodftxlb[/url], [link=http://tostufcnreiz.com/]tostufcnreiz[/link], http://lkmfrhbzenso.com/
  • iyzpfopsg 25 Jun, 07:43 AM

    693o7H , [url=http://jssdzuunmswm.com/]jssdzuunmswm[/url], [link=http://gugqdsxzbafq.com/]gugqdsxzbafq[/link], http://tpnxpdfidnam.com/
  • uqogygtzhzx 26 Jun, 10:14 AM

    iDifGF , [url=http://fxlbldnbneus.com/]fxlbldnbneus[/url], [link=http://oylandfwyewx.com/]oylandfwyewx[/link], http://juqrmsgyqqkm.com/
  • jordan shoes for sale 27 Apr, 11:13 PM

    Buy Jordan 6 in Jordan 7 For Sale the Buy Jordan 7 maintenance of Cheap Jordan 7 the computer, Sichuan BY0008 number of Jordan 6 For Sale private cars will be speeding jordans sneakers U-disk portable photo copying. August.
  • cheap air jordans 4 May, 12:17 AM

    the flight 9 jordans unified examination cases ,parents air jordan 18 retro want to jordan retro 18 know is air jordan retro 18 air jordan flight 9 :what can new jordans the students.
Post a comment!
  1. Formatting options