Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "convert"

Index

Variables

Let NEXT_ID

NEXT_ID: number = 0

Functions

Const asTriples

  • asTriples(obj: any, subject?: any): IterableIterator<any[]>
  • Converts given object into an iterable of triples, with the following conversion rules:

    • Toplevel object keys are used as subjects and MUST each have a plain object as value, where its keys are used as predicates and values as objects (in the SPO sense).
    • Plain objects in SPO object position are translated into unique IDs in order to allow the nested map to become a subject itself. In RDF terms, this is equivalent to BNodes.
    • Arrays in SPO object position cause multiple triples with same subject & predicate to be emitted. If any of the items in the array is a plain object, it will be treated as BNode and transformed as described in the previous rule
    example
    src = {
      "@thi.ng/rstream-query": {
        type: "project",
        author: "toxi",
        tag: ["ES6", "TypeScript", "graph"]
      },
      toxi: {
        type: "person",
        hasAccount: [
          {type: "twitter", id: "toxi"},
          {type: "github", id: "postspectacular"}
        ]
      }
    };
    
    [...asTriples(src)]
    // [ [ '@thi.ng/rstream-query', 'type', 'project' ],
    //   [ '@thi.ng/rstream-query', 'author', 'toxi' ],
    //   [ '@thi.ng/rstream-query', 'tag', 'ES6' ],
    //   [ '@thi.ng/rstream-query', 'tag', 'TypeScript' ],
    //   [ '@thi.ng/rstream-query', 'tag', 'graph' ],
    //   [ 'toxi', 'type', 'person' ],
    //   [ 'toxi', 'hasAccount', '__b0__' ],
    //   [ '__b0__', 'type', 'twitter' ],
    //   [ '__b0__', 'id', 'toxi' ],
    //   [ 'toxi', 'hasAccount', '__b1__' ],
    //   [ '__b1__', 'type', 'github' ],
    //   [ '__b1__', 'id', 'postspectacular' ] ]

    Parameters

    • obj: any

      -

    • Optional subject: any

      internal use only, do not specify!

    Returns IterableIterator<any[]>

Const mapBNode

  • mapBNode(s: any, p: any, o: any): IterableIterator<any[]>
  • Parameters

    • s: any
    • p: any
    • o: any

    Returns IterableIterator<any[]>

Const mapSubject

  • mapSubject(subject: any): (Anonymous function)
  • Parameters

    • subject: any

    Returns (Anonymous function)

Generated using TypeDoc