
op.pattern( subjects as Sequence, predicates as Sequence, objects as Sequence, [systemCols as Object[]] ) as patterndef
This function builds the parameters for the op.fromTriples function. The result is passed to op.fromTriples to project rows from the graph of triples. The columns in a pattern become the columns of the row. The literals in a pattern are used to match triples. You should specify at least one literal in each pattern, usually the predicate. Where a column appears in more than one pattern, the matched triples are joined to form the row. You can specify optional triples with a prototype.joinLeftOuter with a separate op.fromTriples .
| Parameters | |
|---|---|
| subjects | One column or one or more literal values, such as the literal returned by a sem.iri call. The column can be named with a column function such as op.col, op.viewCol, or op.schemaCol. |
| predicates | One column or one or more literal values, such as the literal returned by a sem.iri call. The column can be named with a column function such as op.col, op.viewCol, or op.schemaCol. |
| objects | One column or one or more literal values, such as the literal returned by a sem.iri call. The column can be named with a column function such as op.col, op.viewCol, or op.schemaCol. |
| systemCols | Specifies the result of an op.fragmentIdCol or op.graphCol function to add columns for the fragment id or graph iri. |
const op = require('/MarkLogic/optic');
// prefixer is a factory for sem:iri() constructors in a namespace
const resource = op.prefixer('http://dbpedia.org/resource/');
const foaf = op.prefixer('http://xmlns.com/foaf/0.1/');
const onto = op.prefixer('http://dbpedia.org/ontology/');
const person = op.col('person');
const Plan =
op.fromTriples([
op.pattern(person, onto('birthPlace'), resource('Brooklyn')),
op.pattern(person, foaf("name"), op.col("name"), op.graphCol('graph-id'))
])
.select();
Plan.result();
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.