protegeproject / cellfie-plugin

Protégé plugin for creating OWL ontologies from spreadsheets
105 stars 26 forks source link

Support Mustache Template syntax #102

Open johardi opened 7 years ago

johardi commented 7 years ago

See here.

The translation to use the mustache template syntax is from this:

Individual: @A*(mm:hashEncode)
   Types: NutritionalInformation
   Facts: productName @A*,
          hasTotalFat @B*(xsd:decimal mm:decimalFormat("##0.00")),
          hasSaturatedFat @C*(xsd:decimal mm:decimalFormat("##0.00")),
          hasSugar @I*(xsd:integer),
          hasSodium @F*(xsd:integer mm:capturing("([0-9]+)"))

to this:

Individual: {{@A* | mm:hashEncode}}
   Types: NutritionalInformation
   Facts: productName {{@A*}},
          hasTotalFat {{@B* | xsd:decimal | mm:decimalFormat("##0.00")}},
          hasSaturatedFat {{@C* | xsd:decimal | mm:decimalFormat("##0.00")}},
          hasSugar {{@I* | xsd:integer}},
          hasSodium {{@F* | xsd:integer | mm:capturing("([0-9]+)")}}
matthewhorridge commented 7 years ago

I think it would be good to reuse the Manchester syntax where possible. For example, rather than having

hasTotalFat {{@B* | xsd:decimal | mm:decimalFormat("##0.00")}}

you would have

hasTotalFat {{@B* | mm:decimalFormat("##0.00")}}^^xsd:decimal
johardi commented 7 years ago

Alternative use with an explicit split between data view and template view.

Rule view:

{
  { id: "individualIri",
    iriEncode: "camelCase",
    reference: "A*"
  },
  { id: "productName",
    reference: "A*"
  },
  { id: "totalFat",
    datatype: "xsd:decimal",
    reference: "B*",
    calc: function(x) {
       return decimalFormat(x, "##0.000")
    }
  },
  { id: "saturatedFat",
    datatype: "xsd:decimal",
    reference: "C*",
    calc: function(x) {
       return decimalFormat(x, "##0.000")
    }
  },
  { id: "sugar",
    datatype: "xsd:integer",
    reference: "I*"
  },
 { id: "sodium",
    datatype: "xsd:decimal",
    reference: "F*",
    calc: function(x) {
       return capturing(x, "([0-9]+)", "$1")
    }
  }
}

Rule Template:

Individual: {{individualIri}}
   Types: NutritionalInformation
   Facts: productName {{productName}},
          hasTotalFat {{totalFat}},
          hasSaturatedFat {{saturatedFat}},
          hasSugar {{sugar}},
          hasSodium {{sodium}}
matthewhorridge commented 7 years ago

The idea is that after evaluating the moustache templates, you're left with a valid Manchester Syntax document that could be loaded into Protege or any other tool that supports Manchester Syntax. Therefore, if something, like the datatype for a literal, is expressible in Manchester Syntax it should be expressed in Manchester Syntax and not in a way that only Cellfie/MappingMaster understands.

johardi commented 7 years ago

I agree if the purpose is for viewing compatibility between Manchester Syntax tools. But the evaluator (like MappingMaster) must understand the directives (e.g., datatype) to perform an action, and not just a string attached to the template {{...}}.

Eventually, after the evaluation, MappingMaster will produce a document like:

Individual: nutrition1
   Types: NutritionalInformation
   Facts: productName "Chocolate Fudge",
          hasTotalFat "300.00"^^xsd:decimal,
          hasSaturatedFat "20.99"^^xsd:decimal,
          hasSugar "100"^^xsd:integer,
          hasSodium "5"^^xsd:decimal

and any tools that support Manchester Syntax should be able to read it.