Giter Site home page Giter Site logo

cadl-rdfs's Introduction

cadl-rdf

A prototype emitter for Cadl models to RDF in Turtle format. Uses vocabulary from rdf, rdfs, and schema.org.

Usage

Add the following to your cadl-project.yaml:

emitters:
  "cadl-rdf": true

Then, add import "cadl-rdf" to your Cadl program and add the @rdfns decorator on a namespace or individual models you want to generate RDF for. For example, if your main.cadl file contains

import "cadl-rdf";
using CadlRdf;

@rdfns("ex", "http://example.org/")
model Person {
  name: string;
}

will result in the cadl-output/models.ttl being generated like:

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

ex:Person rdf:type rdfs:Class.
ex:name rdf:type rdf:Property;
    rdfs:domain ex:Person;
    rdfs:range xsd:string.

See the sample directory for a larger example.

Packaging

Until this package is published, it can be consumed by cloning this repository and running:

npm install
npm pack

This will produce a tarball you can pass to npm install to add this emitter to other projects.

Contributing

PRs and other contributions are very welcome!

Building the project

Run these instructions from the root directory (where sample.cadl file is a CADL file you want to emit to RDF):

npm install
npm run build
npx cadl compile sample.cadl --emit cadl-rdf

Running tests

Tests are a work in progress.

cadl-rdfs's People

Watchers

 avatar  avatar

cadl-rdfs's Issues

Implement ENUM

Test the following possible enum declarations will get translated to RDF.

enum Direction {
  North,
  East,
  South,
  West,
}
enum Direction {
  North: "north",
  East: "east",
  South: "south",
  West: "west",
}
enum Foo {
  One: 1,
  Ten: 10,
  Hundred: 100,
  Thousand: 1000,
}
enum Hour {
  Zero = 0,
  Quarter = 0.25,
  Half = 0.5,
  ThreeQuarter = 0.75,
}

Another possibility is composing enums:

enum DirectionExt {
  ...Direction,
  "North East",
  "North West",
  "South East",
  "South West",
}

Implement Decorator functionality

Try out usage of different decorators:

  • deprecated
  • doc - attach a documentation string. Works great with multiline string literals.
  • summary - attach a documentation string. Typically a short single line description.
  • format - specify the data format hint for a string type.
  • pattern
  • knownValues - make a string type with an enum that contains all known values.
  • secret - make a string as a secret value that should be treated carefully to avoid exposure.
  • minLength/maxLength
  • minValue/maxValue

Implement Versioning

If a CADL model has a version then that should be handled by the CADL emitter to RDF.

This task should be implemented after the namespaces are supported.

To add versioning to the project you first need to install the package: npm install @cadl-lang/versioning --save

Once you've done that you can import it in your CADL file.

import "@cadl-lang/versioning"

using Cadl.Versioning;

@versioned(Versions) 
namespace mynamespace {

     model Person {
            @added (Versions.v2) name: string;
            @added (Versions.v3) age: numeric;
     }
}
enum Versions {
     "v1",
     "v2",
     "v3",
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.