@@ -45,8 +45,86 @@ const ruben = paths.create({
4545showPerson (ruben);
4646```
4747
48+ ## Features
49+
50+ ### Using a customised ComunicaEngine
51+
52+ This example uses the comunica engine for local file queries.
53+
54+ ``` JavaScript
55+ const { PathFactory } = require (' ldflex' );
56+ const { default: ComunicaEngine } = require (' @ldflex/comunica' );
57+ const { namedNode } = require (' @rdfjs/data-model' );
58+ const { newEngine: localFileEngine } = require (' @comunica/actor-init-sparql-file' );
59+
60+ // The JSON-LD context for resolving properties
61+ const context = {
62+ " @context" : {
63+ " @vocab" : " http://xmlns.com/foaf/0.1/" ,
64+ " friends" : " knows" ,
65+ }
66+ };
67+ // The query engine and its source
68+ const queryEngine = new ComunicaEngine (
69+ path .join (__dirname , ' ruben-verborgh.ttl' ),
70+ { engine: localFileEngine () }
71+ );
72+ // The object that can create new paths
73+ const paths = new PathFactory ({ context, queryEngine });
74+
75+ async function showPerson (person ) {
76+ console .log (` This person is ${ await person .name } ` );
77+
78+ console .log (` ${ await person .givenName } is friends with:` );
79+ for await (const name of person .friends .givenName )
80+ console .log (` - ${ name} ` );
81+ }
82+
83+ const ruben = paths .create ({
84+ subject: namedNode (' https://ruben.verborgh.org/profile/#me' ),
85+ });
86+ showPerson (ruben);
87+ ```
88+ ### Adding custom options to the ComunicaEngine
89+
90+ Add [ comunica context options] ( https://comunica.dev/docs/query/advanced/context/ ) which are passed to the Comunica Engine.
91+
92+ ``` JavaScript
93+ const { PathFactory } = require (' ldflex' );
94+ const { default: ComunicaEngine } = require (' @ldflex/comunica' );
95+ const { namedNode } = require (' @rdfjs/data-model' );
96+
97+ // The JSON-LD context for resolving properties
98+ const context = {
99+ " @context" : {
100+ " @vocab" : " http://xmlns.com/foaf/0.1/" ,
101+ " friends" : " knows" ,
102+ }
103+ };
104+
105+ // The query engine and its source
106+ const queryEngine = new ComunicaEngine (
107+ ' https://ruben.verborgh.org/profile/' ,
108+ { options: {/* add options here */ } },
109+ );
110+
111+ // The object that can create new paths
112+ const paths = new PathFactory ({ context, queryEngine });
113+
114+ async function showPerson (person ) {
115+ console .log (` This person is ${ await person .name } ` );
116+
117+ console .log (` ${ await person .givenName } is friends with:` );
118+ for await (const name of person .friends .givenName )
119+ console .log (` - ${ name} ` );
120+ }
121+
122+ const ruben = paths .create ({
123+ subject: namedNode (' https://ruben.verborgh.org/profile/#me' ),
124+ });
125+ showPerson (ruben);
126+ ```
127+
48128## License
49129©2018–present
50- [ Ruben Verborgh] ( https://ruben.verborgh.org/ ) ,
51- Joachim Van Herwegen.
52- [ MIT License] ( https://github.com/LDflex/LDflex-Comunica/blob/master/LICENSE.md ) .
130+ [ Ruben Verborgh] ( https://ruben.verborgh.org/ ) , Joachim Van Herwegen, [ Jesse Wright] ( https://github.com/jeswr/ ) . [ MIT License] ( https://github.com/LDflex/LDflex-Comunica/blob/master/LICENSE.md ) .
0 commit comments