@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

@prefix vann:     <http://purl.org/vocab/vann/> .
@prefix voaf:     <http://purl.org/vocommons/voaf#> .
@prefix dce:    <http://purl.org/dc/elements/1.1/> .
@prefix dct:    <http://purl.org/dc/terms/> .
@prefix widoco:	<https://w3id.org/widoco/vocab#>.

@prefix expr: <https://ontology.flandersmake.be/expression/ontology#> .
@base         <https://ontology.flandersmake.be/expression/ontology#> .
@prefix :     <https://ontology.flandersmake.be/expression/ontology#> .

#################################################################
#    Expression ontology
#################################################################

<https://ontology.flandersmake.be/expression/ontology> 
    rdf:type owl:Ontology ;
    owl:versionIRI <https://ontology.flandersmake.be/expression/ontology/1.0.1>;
    owl:versionInfo "1.0.1" ;
    rdfs:label "The Expression Ontology"@en ;
    rdfs:comment "An ontology for numerical expressions";
    vann:preferredNamespaceUri    "https://ontology.flandersmake.be/expression/ontology#" ;
    vann:preferredNamespacePrefix "expr" ;
    dct:created  "2025-10-10"^^xsd:date ;
    dct:modified "2026-03-18"^^xsd:date ;
    dct:issued   "2025-10-10"^^xsd:date ;
    dce:title "The Expression Ontology"@en ;

    dce:abstract '''
An Expression is a resource that associates a value to a list of operand values.
Complex expressions specify an operator and a list of operand terms.
For a complex expression defined by an operator and a list of terms, the
value associated with the expression is obtained by 1) evaluating
the value associated with the operands to every term
and 2) by applying the operator to the set of values obtained this way.
'''@en;

    widoco:introduction '''
The Expression ontology is a vocabulary for describing symbolic expressions, composed of operators, 
operands, parameters.

An expression can be evaluated to a value, when all its parameters have received a value.

The Expression ontology allows to define new functions, without the usage of rules. Such expression
will then be usable with any rule language, provided that the semantics of the expression ontology is
implemented in the targeted rule language.
'''@en;

    dce:description '''
The Expression Ontology allows to describe numerical expressions in rdf.

The following concepts are formalized:
- **Operator**
  - is a predicate, associating a value to a list of values, the operands
- **Built-in**
  - is an Operator provided by the rule language (e.g. `math:sum`)
- **Expression**: 
  - is a resource, identified by an IRI
  - is an Operator like other built-in's
  - is specified with the Expression ontology
    - by an Operator and an ExpressionTerms
    - so only with statements, without new rule
- **ExpressionTerms**: 
   - provides a list of Terms for the Expression
   - defining the set of operands provided to the Operator
- **Terms**: 
  - is a list of Terms
- **Term**
  - a Term of an Expression specifies an operand for the Operator of the Expression
  - the following Term types are provided
    - literals 
      - implicitly for Datatype
      - explicitly with **RawValue**
    - parameters of the Expression
    - subexpressions

```mermaid
classDiagram
  class Operator 
  class Expression 
  Operator <|-- Expression
  class BuiltIn:::owl 
  class List:::owl 
  class Datatype:::owl 

  Operator <|-- BuiltIn

  Expression --> "1" ExpressionTerms : terms
  ExpressionTerms <|-- Terms
  List <|-- Terms
  ExpressionTerms <-- AllParams: type

  Terms --> "0..*" Term : member

  class Term {
    +Number eval(operands)
  }
  Term <-- Param0: type
  Term <-- Param1: type
  class Param {
    +Integer param
  }
  class RawValue {
    rawValue
  }
  Expression --> "1" Operator : operator
  Term <|-- Param
  Term <|-- RawValue
  Term <|-- Datatype
  Term <|-- Expression

  classDef default fill:#f96,color:black
  classDef owl fill:#e9edc9,color:black
```
'''@en.
    
expr:Operator
    rdf:type rdfs:Class;
    rdfs:comment '''
An Operator is a predicate stating that the object value is the result of applying 
the operator to the subject list of operands
'''@en.

expr:Expression
    rdf:type rdfs:Class;
    rdfs:subClassOf expr:Term;
    rdfs:subClassOf expr:Operator;
    rdfs:comment '''An Expression is an Operator, specified by an (other) Operator and a set of Terms, that 
produce a value for a set of operands by first evaluating every term and second by applying 
the (other) operator. An Expression is a also a Term, so can be reused in a outter Expression'''@en.    

expr:operator
    rdf:type rdf:Property;
    rdfs:domain expr:Expression;
    rdfs:range expr:Operator;
    rdfs:comment '''The operator of the expression'''.

expr:terms
    rdf:type rdf:Property;
    rdfs:subPropertyOf expr:subTerms;
    rdfs:domain expr:Expression;
    rdfs:range expr:ExpressionTerms;
    rdfs:comment '''Provides Terms to the Expression (functional)'''@en.

expr:allParams 
    rdf:type expr:ExpressionTerms;
    rdfs:comment '''Evaluates to the list of Params'''@en.

expr:Terms
    rdf:type rdfs:Class;
    rdfs:subClassOf rdf:List;
    rdfs:subClassOf expr:ExpressionTerms;
    rdfs:comment '''A list of Terms'''@en.

expr:Term
    rdf:type rdfs:Class;
    rdfs:label "Operand"@en;
    rdfs:comment '''A term in an Expression, that will be first evaluated, and whose result will be passed to the Operator'''@en.

expr:subTerms
    rdf:type rdf:Property;
    rdfs:domain expr:Expression;
    rdfs:range expr:Terms;
    rdfs:comment '''Any list of subterms of the Expression (from an arbitrary Term to then end), empty list included'''@en.

expr:firstTerm
    rdf:type owl:ObjectProperty;
    rdfs:subPropertyOf rdf:first;
    rdfs:domain expr:Terms;
    rdfs:range expr:Term.

expr:restTerms
    rdf:type owl:ObjectProperty;
    rdfs:subPropertyOf rdf:rest;
    rdfs:domain expr:Terms;
    rdfs:range expr:Terms.

expr:Param
    rdf:type rdfs:Class;
    rdfs:subClassOf expr:Term;
    rdfs:comment '''A Param is a Term that returns the value of some operand'''@en.    

expr:param
    rdf:type rdf:Property;
    rdfs:domain expr:Param;
    rdfs:range xsd:integer.

expr:param0
    rdf:type expr:Term.

expr:param1
    rdf:type expr:Term.

expr:param2
    rdf:type expr:Term.

expr:RawValue
    rdf:type rdfs:Class;
    rdfs:subClassOf expr:Term;
    rdfs:comment '''A RawValue is a Term that returns the raw value associated to it'''@en.    

expr:rawValue
    rdf:type rdf:Property;
    rdfs:domain expr:RawValue.


# Serialization annotations added by generate_docs.py
<https://ontology.flandersmake.be/expression/ontology>
    <https://w3id.org/widoco/vocab#turtleSerialization> "expression.ttl" ;
    <https://w3id.org/widoco/vocab#rdfxmlSerialization> "expression.rdf" ;
    <https://w3id.org/widoco/vocab#ntSerialization> "expression.nt" ;
    <https://w3id.org/widoco/vocab#jsonldSerialization> "expression.jsonld" .
