Author Topic: Typed and Named Trees  (Read 1245 times)

Zero

  • *
  • Autobot
  • ******
  • Posts: 205
  • Fictional character
    • AGI DEV LOG
Typed and Named Trees
« on: October 18, 2015, 02:40:55 PM »
Hi all,

I was looking for a file format that would be somewhere between INI files (too simple) and XML (too... XMLish). Here is what I came up with. I call it TNT, short for Typed and Named Trees. It's heavily inspired from BBCode.

Code: [Select]
  [a type = a label]

    types and labels can contain spaces
    labels can be identifiers or glob patterns, or anything

    [type only]

      labels are optional
      nesting is allowed and [inline] indentation doesn't matter [/inline]
 
    [/type only]

    and we also have [empty tags/]

  [/a type]

It is less expressive than XML since we get rid of attributes. I know, TNT should not exist: we're supposed to follow standards, but I can't help it.  :idiot2: :)

EDIT:

These .tnt files could be the building blocks of a simple thinkbot system.
- From AIML I want to keep the trigger/template idea with glob patterns and star-tags.
- Unlike chatbots, a thinkbot won't generate speech directly, it will generate thoughts instead. Thoughts call other thougths. Eventually, thoughts call action, like speech.
- For scripting, I'll use my-basic which has no square brackets in its syntax (and which feels like I'm 10 again), so user can insert star-tags inside code.
- The whole thing should be mounted on libuv for async and good IO.
- There should be a focus system, but I still don't know how. It has to be straightforward.
« Last Edit: October 18, 2015, 03:48:11 PM by Zero »
PRO|STAMINA [ programming game ]
AGI DEV LOG [ In Goto We Trust ]

infurl

  • *
  • Autobot
  • ******
  • Posts: 221
  • Humans will disappoint you.
    • Home Page
Re: Typed and Named Trees
« Reply #1 on: October 18, 2015, 09:44:38 PM »
I was looking for a file format that would be somewhere between INI files (too simple) and XML (too... XMLish). Here is what I came up with. I call it TNT, short for Typed and Named Trees. It's heavily inspired from BBCode.

I don't actually mind XML and do a lot of work with it, but if you want comparable power and a simple syntax then shouldn't you be looking at JSON which has achieved very wide-spread use?

Art

  • At the end of the game, the King and Pawn go into the same box.
  • *
  • Hal 4000
  • ******************
  • Posts: 4201
Re: Typed and Named Trees
« Reply #2 on: October 18, 2015, 11:37:37 PM »
Wow! For a moment there your Subject Title had me going back through my memory trying to recall the various Tree names like: Ash, Aspen, Basswood, Bayberry, Beech, Birch, Cedar, Chestnut, Dogwood, Elm, etc., etc.

Actually quite an exhaustive list...nothing to "bark" about!  :2funny: Never mind...I'll Leaf you alone! ;)
In the world of AI, it's the thought that counts!

Zero

  • *
  • Autobot
  • ******
  • Posts: 205
  • Fictional character
    • AGI DEV LOG
Re: Typed and Named Trees
« Reply #3 on: October 19, 2015, 06:41:52 AM »
 ;D That's also what my search engine told me first!! God it's hard to create english names when you're not english!  ::)

@infurl
Yes, there are a lot of formats already. In pure JSON, user would have to escape double-quotes (which are part of my-basic's syntax) and newlines. It wouldn't feel very fluent. There's also TOML, which is very nice, but I don't like its double-square-brackets thing.

I wanted something simple... What I like here is that you can describe TNT in 10 lines!

EDIT:

Thanks for your input, infurl. You gave me this idea: for storing the TNT when I'll parse it, I'll use a json library! So, I'll have a ready-made data structure, and I can export it easily in json!

« Last Edit: October 19, 2015, 03:35:53 PM by Zero »
PRO|STAMINA [ programming game ]
AGI DEV LOG [ In Goto We Trust ]

Zero

  • *
  • Autobot
  • ******
  • Posts: 205
  • Fictional character
    • AGI DEV LOG
Re: Typed and Named Trees
« Reply #4 on: October 20, 2015, 06:19:50 AM »
The previous tnt sample would translate to the following JSON:
Code: [Select]
  [
    {
      "istag" : TRUE,
      "type" : "a type",
      "label" : "a label",
      "content" :
      [
        {
          "istag" : FALSE,
          "text" : "types and labels can contain spaces \n labels can be identifiers or glob patterns, or anything"
        },
        {
          "istag" : TRUE,
          "type : "type only",
          "label" : FALSE,
          "content" :
          [
            {
              "istag" : FALSE,
              "text" : "labels are optional \n nesting is allowed and"
            },
            {
              "istag" : TRUE,
              "type" : "inline",
              "label" : FALSE,
              "content" :
              [
                {
                  "istag" : FALSE,
                  "text" : "indentation doesn't matter"
                }
              ]
            }
          ]
        },
        {
          "istag" : FALSE,
          "text" : "and we also have"
        },
        {
          "istag" : TRUE,
          "type" : "empty tags",
          "label" : FALSE,
          "content" : FALSE
        }
      ]
    }
  ]

EDIT: There should be support for a few useful specific syntaxes inside certain tags, like string lists, n-ary relations, an RDF syntax, ...etc.
« Last Edit: October 20, 2015, 06:46:08 AM by Zero »
PRO|STAMINA [ programming game ]
AGI DEV LOG [ In Goto We Trust ]

Zero

  • *
  • Autobot
  • ******
  • Posts: 205
  • Fictional character
    • AGI DEV LOG
Re: Typed and Named Trees
« Reply #5 on: October 23, 2015, 07:58:20 AM »
Hi!

In PEGjs, the following grammar...

Code: [Select]

Content
= (Element / Text)*

Element
= startTag:sTag content:Content endTag:eTag {
    if (startTag.type != endTag.type) {
      throw new Error(
        "Expected [/" + startTag + "] but [/" + endTag + "] found."
      );
    }
    return {
      istag:   startTag.istag,
      type:    startTag.type,
      label:   startTag.label,
      content: content
    };
  }
/ startTag:selfTag {
    return {
      istag:   startTag.istag,
      type:    startTag.type,
      label:   startTag.label,
    };
  }

sTag
= [ \n\t]* "[" type:TagType "]" [ \n\t]* { return {istag:true,type:type,label:false}; }
/ [ \n\t]* "[" type:TagType "=" lab:label "]" [ \n\t]* { return {istag:true,type:type,label:lab}; }

label
= chars:[^/\[\]=]*  {return chars.join("").trim();}

selfTag
= [ \n\t]* "[" type:TagType "/]" [ \n\t]* { return {istag:true,type:type,label:false}; }
/ [ \n\t]* "[" type:TagType "=" lab:label "/]" [ \n\t]* { return {istag:true,type:type,label:lab}; }

eTag
= [ \n\t]* "[/" type:TagType "]" [ \n\t]* { return {type:type}; }

TagType
= chars:[a-zA-Z0-9 ]+ { return chars.join("").trim(); }

Text
= chars:([^\[\]])+ { return {istag:false,text:chars.join("").replace(/[ \t]+/g, ' ').replace(/\n+/g,'\n').trim()};}


...will translate this...

Code: [Select]

  [a type = a label]

    types and labels can contain spaces
labels can be identifiers or glob patterns, or anything

    [type only]

  labels are optional
  nesting is allowed and [inline] indentation doesn't matter [/inline]
 
    [/type only]

and we also have [empty tags/]

  [/a type]


...to this...

Code: [Select]
[
   {
      "istag": true,
      "type": "a type",
      "label": "a label",
      "content": [
         {
            "istag": false,
            "text": "types and labels can contain spaces
 labels can be identifiers or glob patterns, or anything"
         },
         {
            "istag": true,
            "type": "type only",
            "label": false,
            "content": [
               {
                  "istag": false,
                  "text": "labels are optional
 nesting is allowed and"
               },
               {
                  "istag": true,
                  "type": "inline",
                  "label": false,
                  "content": [
                     {
                        "istag": false,
                        "text": "indentation doesn't matter"
                     }
                  ]
               }
            ]
         },
         {
            "istag": false,
            "text": "and we also have"
         },
         {
            "istag": true,
            "type": "empty tags",
            "label": false
         }
      ]
   }
]
PRO|STAMINA [ programming game ]
AGI DEV LOG [ In Goto We Trust ]

 

Welcome

Please login or register.



Login with username, password and session length
UK Royal Society wants to hear your thoughts on machine learning
by 8pla.net (Robotics News)
March 21, 2017, 05:09:24 PM
Reactions from experts: Robotics and tech to receive funding boost from UK government
by Tyler (Robotics News)
March 09, 2017, 10:49:36 PM
Should an artificial intelligence be allowed to get a patent?
by Tyler (Robotics News)
March 09, 2017, 04:49:21 PM
Supporting Women in Robotics on International Women’s Day.. and beyond.
by Tyler (Robotics News)
March 08, 2017, 10:48:42 PM
Revolutionizing the way we build via digital fabrication technologies
by Tyler (Robotics News)
March 08, 2017, 04:48:16 PM
Mayfield Robotics to introduce enhanced interactions with Kuri
by Tyler (Robotics News)
March 07, 2017, 10:49:18 PM
Programming for robotics: Introduction to ROS
by Tyler (Robotics News)
March 07, 2017, 04:48:51 PM

Users Online

36 Guests, 3 Users
Users active in past 15 minutes:
Freddy, magdrummond, kei10
[Administrator]
[Roomba]
[Trusty Member]

Most Online Today: 61. Most Online Ever: 208 (August 27, 2008, 08:24:30 AM)

Articles