@thomasfosterau/effect-rdf 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2250 -1
- package/dist/Algebra-CGG4oae3.mjs +433 -0
- package/dist/Algebra-CGG4oae3.mjs.map +1 -0
- package/dist/Algebra-uGsIEOUA.d.mts +446 -0
- package/dist/Ast-CPRZmBvk.mjs +552 -0
- package/dist/Ast-CPRZmBvk.mjs.map +1 -0
- package/dist/Ast-vcw2W-lf.d.mts +827 -0
- package/dist/Bindings-Ck3m7JRC.mjs +249 -0
- package/dist/Bindings-Ck3m7JRC.mjs.map +1 -0
- package/dist/Bindings-DiKpBd7f.d.mts +153 -0
- package/dist/ClientErrors-CpXdFX5u.mjs +128 -0
- package/dist/ClientErrors-CpXdFX5u.mjs.map +1 -0
- package/dist/ClientErrors-D4IZHUM-.d.mts +101 -0
- package/dist/ClientFormats-CXomkXLV.mjs +73 -0
- package/dist/ClientFormats-CXomkXLV.mjs.map +1 -0
- package/dist/ClientFormats-Dm57ZPwR.d.mts +36 -0
- package/dist/Csv2Json-DynEcwCh.mjs +194 -0
- package/dist/Csv2Json-DynEcwCh.mjs.map +1 -0
- package/dist/Csv2Json-aXNVDoXQ.d.mts +40 -0
- package/dist/Csv2Rdf-8maXP6mt.d.mts +41 -0
- package/dist/Csv2Rdf-DuSEkaKE.mjs +161 -0
- package/dist/Csv2Rdf-DuSEkaKE.mjs.map +1 -0
- package/dist/Dataset-BlmlcI7J.mjs +782 -0
- package/dist/Dataset-BlmlcI7J.mjs.map +1 -0
- package/dist/Dataset-DS3ESOcO.d.mts +426 -0
- package/dist/Dataset.d.mts +2 -0
- package/dist/Dataset.mjs +1 -0
- package/dist/Datatype-CxMpamHC.d.mts +212 -0
- package/dist/Datatype-DQvkNkiH.mjs +1001 -0
- package/dist/Datatype-DQvkNkiH.mjs.map +1 -0
- package/dist/Dialect-8ChFj5EX.d.mts +113 -0
- package/dist/Dialect-CzVH38uo.mjs +165 -0
- package/dist/Dialect-CzVH38uo.mjs.map +1 -0
- package/dist/DocumentLoader-D3lZREnB.mjs +346 -0
- package/dist/DocumentLoader-D3lZREnB.mjs.map +1 -0
- package/dist/DocumentLoader-ZUCEVrW5.d.mts +178 -0
- package/dist/DublinCore-AnwqxRx6.mjs +137 -0
- package/dist/DublinCore-AnwqxRx6.mjs.map +1 -0
- package/dist/DublinCore-Dq-tVA5d.d.mts +119 -0
- package/dist/Engine-CYPB3g4h.d.mts +144 -0
- package/dist/Engine-DF8PN7g-.mjs +872 -0
- package/dist/Engine-DF8PN7g-.mjs.map +1 -0
- package/dist/Errors-CMdV1RhU.mjs +37 -0
- package/dist/Errors-CMdV1RhU.mjs.map +1 -0
- package/dist/Errors-u2bDjUeM.d.mts +30 -0
- package/dist/Evaluator-DEsU4d1o.d.mts +50 -0
- package/dist/Evaluator-DOY2-guC.mjs +281 -0
- package/dist/Evaluator-DOY2-guC.mjs.map +1 -0
- package/dist/Exif-CpqniYQd.d.mts +78 -0
- package/dist/Exif-DjkCfEB-.mjs +89 -0
- package/dist/Exif-DjkCfEB-.mjs.map +1 -0
- package/dist/Expression-BIMMvduQ.mjs +230 -0
- package/dist/Expression-BIMMvduQ.mjs.map +1 -0
- package/dist/Expression-W8A9cyX7.d.mts +89 -0
- package/dist/Extract-Bop85jES.mjs +220 -0
- package/dist/Extract-Bop85jES.mjs.map +1 -0
- package/dist/Extract-C_pCvuTC.d.mts +88 -0
- package/dist/Federation-BcNrozc1.d.mts +52 -0
- package/dist/Federation-CHScBkaK.mjs +130 -0
- package/dist/Federation-CHScBkaK.mjs.map +1 -0
- package/dist/Functions-AvjNcId_.mjs +1346 -0
- package/dist/Functions-AvjNcId_.mjs.map +1 -0
- package/dist/Functions-OQJZP-F6.d.mts +111 -0
- package/dist/Generator-C52mmq01.d.mts +50 -0
- package/dist/Generator-D3utCJC7.mjs +205 -0
- package/dist/Generator-D3utCJC7.mjs.map +1 -0
- package/dist/Grammar-CPlSxGH6.mjs +200 -0
- package/dist/Grammar-CPlSxGH6.mjs.map +1 -0
- package/dist/Grammar-CRhnRoCu.d.mts +148 -0
- package/dist/Grammar-D6jZdJQ3.d.mts +169 -0
- package/dist/Grammar-mQ8CgE1M.mjs +258 -0
- package/dist/Grammar-mQ8CgE1M.mjs.map +1 -0
- package/dist/GraphStore-DhUa4nFO.d.mts +45 -0
- package/dist/GraphStore-DvbqwKy1.mjs +212 -0
- package/dist/GraphStore-DvbqwKy1.mjs.map +1 -0
- package/dist/Iri-BB8Ks-BF.d.mts +84 -0
- package/dist/Iri-Cr92gsQV.mjs +232 -0
- package/dist/Iri-Cr92gsQV.mjs.map +1 -0
- package/dist/Iri.d.mts +2 -0
- package/dist/Iri.mjs +1 -0
- package/dist/Isomorphism-B6qTY-xy.d.mts +28 -0
- package/dist/Isomorphism-BmqxhKyJ.mjs +232 -0
- package/dist/Isomorphism-BmqxhKyJ.mjs.map +1 -0
- package/dist/Isomorphism-DInKnWIy.mjs +390 -0
- package/dist/Isomorphism-DInKnWIy.mjs.map +1 -0
- package/dist/Isomorphism-DvSfZXLR.d.mts +37 -0
- package/dist/Isomorphism.d.mts +2 -0
- package/dist/Isomorphism.mjs +1 -0
- package/dist/JsonLd-DOwS2FHg.mjs +2836 -0
- package/dist/JsonLd-DOwS2FHg.mjs.map +1 -0
- package/dist/JsonLd-DobFrQNa.d.mts +242 -0
- package/dist/JsonLdError-C9J-BxfG.mjs +106 -0
- package/dist/JsonLdError-C9J-BxfG.mjs.map +1 -0
- package/dist/JsonLdError-DSOfHkOy.d.mts +43 -0
- package/dist/LanguageTag-BCu8rcmX.d.mts +38 -0
- package/dist/LanguageTag-BcOpMGZ4.mjs +89 -0
- package/dist/LanguageTag-BcOpMGZ4.mjs.map +1 -0
- package/dist/LanguageTag.d.mts +2 -0
- package/dist/LanguageTag.mjs +1 -0
- package/dist/Lexical-Cg0JHrf6.mjs +243 -0
- package/dist/Lexical-Cg0JHrf6.mjs.map +1 -0
- package/dist/Lexical-D3zySYVS.d.mts +163 -0
- package/dist/Manifest-B6xf6mUc.mjs +148 -0
- package/dist/Manifest-B6xf6mUc.mjs.map +1 -0
- package/dist/Manifest-DQUMRBFr.d.mts +98 -0
- package/dist/Mapping-BgG74x3U.d.mts +63 -0
- package/dist/Mapping-Dc1ZGirk.mjs +259 -0
- package/dist/Mapping-Dc1ZGirk.mjs.map +1 -0
- package/dist/Mcp-1DwTTKOK.mjs +48 -0
- package/dist/Mcp-1DwTTKOK.mjs.map +1 -0
- package/dist/Mcp-d-pX9erx.d.mts +25 -0
- package/dist/Message-CK_DGQuu.mjs +95 -0
- package/dist/Message-CK_DGQuu.mjs.map +1 -0
- package/dist/Message-fIvTJSXM.d.mts +49 -0
- package/dist/Metadata-BbffwGDZ.mjs +445 -0
- package/dist/Metadata-BbffwGDZ.mjs.map +1 -0
- package/dist/Metadata-CEt3yc1-.d.mts +901 -0
- package/dist/Metadata-D4HsQNXr.mjs +1273 -0
- package/dist/Metadata-D4HsQNXr.mjs.map +1 -0
- package/dist/Metadata-nzS7QKRj.d.mts +350 -0
- package/dist/Model-DaMmxurZ.d.mts +293 -0
- package/dist/Model-DlPzRYhF.mjs +528 -0
- package/dist/Model-DlPzRYhF.mjs.map +1 -0
- package/dist/N3-BzyV-KIH.mjs +974 -0
- package/dist/N3-BzyV-KIH.mjs.map +1 -0
- package/dist/N3-DSLnonDn.d.mts +100 -0
- package/dist/NQuads-C1VBOJ3-.mjs +117 -0
- package/dist/NQuads-C1VBOJ3-.mjs.map +1 -0
- package/dist/NQuads-FjFZikFg.d.mts +76 -0
- package/dist/NTriples-D-kLSEAf.mjs +120 -0
- package/dist/NTriples-D-kLSEAf.mjs.map +1 -0
- package/dist/NTriples-D34OspfW.d.mts +76 -0
- package/dist/Namespace-ClTUO_ya.d.mts +42 -0
- package/dist/Namespace-DHFIsORd.mjs +75 -0
- package/dist/Namespace-DHFIsORd.mjs.map +1 -0
- package/dist/Namespace.d.mts +2 -0
- package/dist/Namespace.mjs +1 -0
- package/dist/Namespaces-Bz85vpjW.mjs +235 -0
- package/dist/Namespaces-Bz85vpjW.mjs.map +1 -0
- package/dist/Namespaces-C1jW6EDo.d.mts +178 -0
- package/dist/Optimizer-BWWQRQPY.mjs +168 -0
- package/dist/Optimizer-BWWQRQPY.mjs.map +1 -0
- package/dist/Optimizer-DUpUow6k.d.mts +26 -0
- package/dist/Options-BLBGL4HE.mjs +72 -0
- package/dist/Options-BLBGL4HE.mjs.map +1 -0
- package/dist/Options-BommQwP9.d.mts +127 -0
- package/dist/Packet-CA76wVX3.mjs +197 -0
- package/dist/Packet-CA76wVX3.mjs.map +1 -0
- package/dist/Packet-Cy5g6XuW.d.mts +130 -0
- package/dist/Parser-p1Gyr0QN.d.mts +85 -0
- package/dist/Parser-xARsOWXk.mjs +1317 -0
- package/dist/Parser-xARsOWXk.mjs.map +1 -0
- package/dist/Path-B20Yp8KE.mjs +284 -0
- package/dist/Path-B20Yp8KE.mjs.map +1 -0
- package/dist/Path-DRB8e-Zn.d.mts +181 -0
- package/dist/Pdf-B9RZn--8.d.mts +77 -0
- package/dist/Pdf-CKK6dkZn.mjs +89 -0
- package/dist/Pdf-CKK6dkZn.mjs.map +1 -0
- package/dist/PdfA-CUjSuntT.d.mts +109 -0
- package/dist/PdfA-CleOhuL6.mjs +124 -0
- package/dist/PdfA-CleOhuL6.mjs.map +1 -0
- package/dist/Photoshop-CiHo80qV.mjs +233 -0
- package/dist/Photoshop-CiHo80qV.mjs.map +1 -0
- package/dist/Photoshop-udKZ0I3N.d.mts +204 -0
- package/dist/PrefixMap-BHFPDLO-.mjs +103 -0
- package/dist/PrefixMap-BHFPDLO-.mjs.map +1 -0
- package/dist/PrefixMap-BMlXrWNd.d.mts +64 -0
- package/dist/PrefixMap.d.mts +2 -0
- package/dist/PrefixMap.mjs +1 -0
- package/dist/Processor-CMmecFsb.mjs +198 -0
- package/dist/Processor-CMmecFsb.mjs.map +1 -0
- package/dist/Processor-FJPvO0CB.d.mts +435 -0
- package/dist/Protocol-BA7OkNgp.mjs +202 -0
- package/dist/Protocol-BA7OkNgp.mjs.map +1 -0
- package/dist/Protocol-DlSoiIKB.d.mts +108 -0
- package/dist/ProtocolErrors-Ckfejnl6.d.mts +84 -0
- package/dist/ProtocolErrors-czDPVcX5.mjs +129 -0
- package/dist/ProtocolErrors-czDPVcX5.mjs.map +1 -0
- package/dist/Query-D9A6LOpP.mjs +364 -0
- package/dist/Query-D9A6LOpP.mjs.map +1 -0
- package/dist/Query-KqSkTYyG.d.mts +96 -0
- package/dist/QueryBuilder-BLK9Vfbz.mjs +674 -0
- package/dist/QueryBuilder-BLK9Vfbz.mjs.map +1 -0
- package/dist/QueryBuilder-DUqh4ECe.d.mts +529 -0
- package/dist/RdfJs-D6-49XB5.mjs +86 -0
- package/dist/RdfJs-D6-49XB5.mjs.map +1 -0
- package/dist/RdfJs-DXFqdWrd.d.mts +76 -0
- package/dist/RdfJs.d.mts +2 -0
- package/dist/RdfJs.mjs +1 -0
- package/dist/RdfJson-5aKPDlPS.d.mts +297 -0
- package/dist/RdfJson-BNocgW4f.mjs +548 -0
- package/dist/RdfJson-BNocgW4f.mjs.map +1 -0
- package/dist/RdfXml-DJ9G4gOq.mjs +1014 -0
- package/dist/RdfXml-DJ9G4gOq.mjs.map +1 -0
- package/dist/RdfXml-_N7yxWEp.d.mts +149 -0
- package/dist/Rdfs-BRVPsAjc.d.mts +84 -0
- package/dist/Rdfs-CyY2wVHI.mjs +167 -0
- package/dist/Rdfs-CyY2wVHI.mjs.map +1 -0
- package/dist/Rdfs.d.mts +2 -0
- package/dist/Rdfs.mjs +1 -0
- package/dist/Reasoner-BxYhx9s7.d.mts +94 -0
- package/dist/Reasoner-Cw90zrjv.mjs +798 -0
- package/dist/Reasoner-Cw90zrjv.mjs.map +1 -0
- package/dist/Reification-BmN4EfnM.d.mts +40 -0
- package/dist/Reification-dpqQvjDE.mjs +82 -0
- package/dist/Reification-dpqQvjDE.mjs.map +1 -0
- package/dist/Reification.d.mts +2 -0
- package/dist/Reification.mjs +1 -0
- package/dist/Report-XHs8htzK.mjs +121 -0
- package/dist/Report-XHs8htzK.mjs.map +1 -0
- package/dist/Report-hcXsc_19.d.mts +115 -0
- package/dist/Resource-B1cI8FyJ.d.mts +218 -0
- package/dist/Resource-sIEeNh15.mjs +374 -0
- package/dist/Resource-sIEeNh15.mjs.map +1 -0
- package/dist/Resource.d.mts +2 -0
- package/dist/Resource.mjs +1 -0
- package/dist/Results-BVNEC-Wt.d.mts +277 -0
- package/dist/Results-peJjGA2V.mjs +621 -0
- package/dist/Results-peJjGA2V.mjs.map +1 -0
- package/dist/ResultsStream-BhF0OcNn.mjs +639 -0
- package/dist/ResultsStream-BhF0OcNn.mjs.map +1 -0
- package/dist/ResultsStream-toYMXrOe.d.mts +100 -0
- package/dist/SemAct-CDchtk49.d.mts +96 -0
- package/dist/SemAct-CmyT4yI8.mjs +118 -0
- package/dist/SemAct-CmyT4yI8.mjs.map +1 -0
- package/dist/Serialization-DP9H5bYQ.mjs +514 -0
- package/dist/Serialization-DP9H5bYQ.mjs.map +1 -0
- package/dist/Serialization-Df8iVauT.d.mts +392 -0
- package/dist/Serialization.d.mts +2 -0
- package/dist/Serialization.mjs +1 -0
- package/dist/ServerFormats-CrRnjjf6.mjs +64 -0
- package/dist/ServerFormats-CrRnjjf6.mjs.map +1 -0
- package/dist/ServerFormats-DjC9NsO_.d.mts +36 -0
- package/dist/ServiceDescription-BERsvg-k.d.mts +54 -0
- package/dist/ServiceDescription-Dq5hxeGy.mjs +97 -0
- package/dist/ServiceDescription-Dq5hxeGy.mjs.map +1 -0
- package/dist/ShExC-Ctf-06CL.d.mts +67 -0
- package/dist/ShExC-DJbB19i3.mjs +1181 -0
- package/dist/ShExC-DJbB19i3.mjs.map +1 -0
- package/dist/ShExError-BeYFD9rv.d.mts +61 -0
- package/dist/ShExError-CVtq2NnM.mjs +64 -0
- package/dist/ShExError-CVtq2NnM.mjs.map +1 -0
- package/dist/ShExJ-C1u_wgyD.d.mts +531 -0
- package/dist/ShExJ-COiPd9Xw.mjs +532 -0
- package/dist/ShExJ-COiPd9Xw.mjs.map +1 -0
- package/dist/ShExR-ByR4mCh-.mjs +480 -0
- package/dist/ShExR-ByR4mCh-.mjs.map +1 -0
- package/dist/ShExR-CqONNNBz.d.mts +40 -0
- package/dist/ShapeMap-C422pxKl.d.mts +140 -0
- package/dist/ShapeMap-CsgKxB2G.mjs +181 -0
- package/dist/ShapeMap-CsgKxB2G.mjs.map +1 -0
- package/dist/Shapes-18GjfyBV.mjs +597 -0
- package/dist/Shapes-18GjfyBV.mjs.map +1 -0
- package/dist/Shapes-BQFDFc4Q.d.mts +306 -0
- package/dist/Sparql-BiYFMSpl.mjs +29 -0
- package/dist/Sparql-BiYFMSpl.mjs.map +1 -0
- package/dist/Sparql-DecpWTPh.d.mts +97 -0
- package/dist/SparqlClient-C_CjXbwj.mjs +333 -0
- package/dist/SparqlClient-C_CjXbwj.mjs.map +1 -0
- package/dist/SparqlClient-UPc88SHy.d.mts +290 -0
- package/dist/SparqlServer-CbUW-pVj.d.mts +71 -0
- package/dist/SparqlServer-Db7w7Cll.mjs +308 -0
- package/dist/SparqlServer-Db7w7Cll.mjs.map +1 -0
- package/dist/SqlStore-BBqFx-Wl.mjs +684 -0
- package/dist/SqlStore-BBqFx-Wl.mjs.map +1 -0
- package/dist/SqlStore-CCJo5I-e.d.mts +117 -0
- package/dist/Store-D0jmVfb3.d.mts +166 -0
- package/dist/Store-DH3Ow1GO.mjs +162 -0
- package/dist/Store-DH3Ow1GO.mjs.map +1 -0
- package/dist/Structure-BjMo4Bkc.mjs +334 -0
- package/dist/Structure-BjMo4Bkc.mjs.map +1 -0
- package/dist/Structure-n4CmDiab.d.mts +63 -0
- package/dist/Table-BGgm9nbM.mjs +538 -0
- package/dist/Table-BGgm9nbM.mjs.map +1 -0
- package/dist/Table-C3reiVrb.d.mts +261 -0
- package/dist/Term-B_4ezyXq.d.mts +619 -0
- package/dist/Term-CFLG1qu4.mjs +991 -0
- package/dist/Term-CFLG1qu4.mjs.map +1 -0
- package/dist/Term.d.mts +2 -0
- package/dist/Term.mjs +1 -0
- package/dist/TermCodec-CDZiEztW.mjs +397 -0
- package/dist/TermCodec-CDZiEztW.mjs.map +1 -0
- package/dist/TermCodec-_03bDXr0.d.mts +209 -0
- package/dist/TermCodec.d.mts +2 -0
- package/dist/TermCodec.mjs +1 -0
- package/dist/TermJson-BOPe0yve.d.mts +232 -0
- package/dist/TermJson-FAg3lvjl.mjs +142 -0
- package/dist/TermJson-FAg3lvjl.mjs.map +1 -0
- package/dist/TermJson.d.mts +2 -0
- package/dist/TermJson.mjs +1 -0
- package/dist/TermSchema-Bn9CoaYA.mjs +30 -0
- package/dist/TermSchema-Bn9CoaYA.mjs.map +1 -0
- package/dist/TermSchema-DBO6MroX.d.mts +6 -0
- package/dist/Testing-B-aPCpmu.mjs +63 -0
- package/dist/Testing-B-aPCpmu.mjs.map +1 -0
- package/dist/Testing-CF6s8P3O.d.mts +53 -0
- package/dist/Tiff-CR-2QeSI.d.mts +148 -0
- package/dist/Tiff-DlsOlZPM.mjs +169 -0
- package/dist/Tiff-DlsOlZPM.mjs.map +1 -0
- package/dist/Tools-7MdRKccr.d.mts +583 -0
- package/dist/Tools-ryxphZbI.mjs +329 -0
- package/dist/Tools-ryxphZbI.mjs.map +1 -0
- package/dist/Translate-B0YKKANS.d.mts +37 -0
- package/dist/Translate-gzWPq0Ia.mjs +308 -0
- package/dist/Translate-gzWPq0Ia.mjs.map +1 -0
- package/dist/Translation-DC9rLm2y.mjs +1535 -0
- package/dist/Translation-DC9rLm2y.mjs.map +1 -0
- package/dist/Translation-K4L9XBqX.d.mts +103 -0
- package/dist/TriG-BkqtqZ6Y.mjs +125 -0
- package/dist/TriG-BkqtqZ6Y.mjs.map +1 -0
- package/dist/TriG-xDjdDatp.d.mts +86 -0
- package/dist/Turtle-Bv1_bisW.d.mts +85 -0
- package/dist/Turtle-CZVUOtwl.mjs +133 -0
- package/dist/Turtle-CZVUOtwl.mjs.map +1 -0
- package/dist/ValidationReport-DBdJshW5.mjs +285 -0
- package/dist/ValidationReport-DBdJshW5.mjs.map +1 -0
- package/dist/ValidationReport-Dx3WxY0h.d.mts +192 -0
- package/dist/Validator-227ff9Rn.d.mts +179 -0
- package/dist/Validator-BzXMKDeJ.mjs +1162 -0
- package/dist/Validator-BzXMKDeJ.mjs.map +1 -0
- package/dist/Validator-Dl8cih5V.d.mts +207 -0
- package/dist/Validator-DmUfMbpL.mjs +568 -0
- package/dist/Validator-DmUfMbpL.mjs.map +1 -0
- package/dist/Vocab-DceKywpq.mjs +168 -0
- package/dist/Vocab-DceKywpq.mjs.map +1 -0
- package/dist/Vocab-Df-L-IwZ.d.mts +46 -0
- package/dist/Vocab-Do56UgBX.d.mts +81 -0
- package/dist/Vocab-TfpWG1Ne.mjs +118 -0
- package/dist/Vocab-TfpWG1Ne.mjs.map +1 -0
- package/dist/Vocab.d.mts +2 -0
- package/dist/Vocab.mjs +1 -0
- package/dist/Vocabulary-C6-GPOy4.d.mts +22 -0
- package/dist/Vocabulary-CnQl-_Z4.mjs +179 -0
- package/dist/Vocabulary-CnQl-_Z4.mjs.map +1 -0
- package/dist/Xml-B7iihYCS.mjs +976 -0
- package/dist/Xml-B7iihYCS.mjs.map +1 -0
- package/dist/Xml-CmfHS7SW.d.mts +267 -0
- package/dist/Xmp-D7CKA7MZ.d.mts +111 -0
- package/dist/Xmp-DCGN9pOD.mjs +307 -0
- package/dist/Xmp-DCGN9pOD.mjs.map +1 -0
- package/dist/XmpBasic-CP38jpR_.mjs +73 -0
- package/dist/XmpBasic-CP38jpR_.mjs.map +1 -0
- package/dist/XmpBasic-Cmbe53rQ.d.mts +64 -0
- package/dist/XmpMM-BfL_TgJF.mjs +73 -0
- package/dist/XmpMM-BfL_TgJF.mjs.map +1 -0
- package/dist/XmpMM-Dqm3IX8p.d.mts +63 -0
- package/dist/XmpRights-BKPtoI5L.mjs +73 -0
- package/dist/XmpRights-BKPtoI5L.mjs.map +1 -0
- package/dist/XmpRights-CaALZQz2.d.mts +63 -0
- package/dist/Xsd-Cdgx5zRB.mjs +405 -0
- package/dist/Xsd-Cdgx5zRB.mjs.map +1 -0
- package/dist/Xsd-D2elNhSm.d.mts +187 -0
- package/dist/Xsd.d.mts +2 -0
- package/dist/Xsd.mjs +1 -0
- package/dist/accessors-CEjaojuQ.mjs +28 -0
- package/dist/accessors-CEjaojuQ.mjs.map +1 -0
- package/dist/codec-Lb2T96rv.d.mts +20 -0
- package/dist/codec-QNo7IdJF.mjs +389 -0
- package/dist/codec-QNo7IdJF.mjs.map +1 -0
- package/dist/csvw/Csv2Json.d.mts +2 -0
- package/dist/csvw/Csv2Json.mjs +1 -0
- package/dist/csvw/Csv2Rdf.d.mts +2 -0
- package/dist/csvw/Csv2Rdf.mjs +1 -0
- package/dist/csvw/Datatype.d.mts +2 -0
- package/dist/csvw/Datatype.mjs +1 -0
- package/dist/csvw/Metadata.d.mts +2 -0
- package/dist/csvw/Metadata.mjs +1 -0
- package/dist/csvw/Processor.d.mts +2 -0
- package/dist/csvw/Processor.mjs +1 -0
- package/dist/csvw/Report.d.mts +2 -0
- package/dist/csvw/Report.mjs +1 -0
- package/dist/csvw/Table.d.mts +2 -0
- package/dist/csvw/Table.mjs +1 -0
- package/dist/csvw/index.d.mts +8 -0
- package/dist/csvw/index.mjs +8 -0
- package/dist/index-Cms2TYfC.d.mts +16 -0
- package/dist/index-Ct8xFmRs.d.mts +7 -0
- package/dist/index-D4QFwOjm.d.mts +28 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.mjs +17 -0
- package/dist/jsonld/DocumentLoader.d.mts +2 -0
- package/dist/jsonld/DocumentLoader.mjs +1 -0
- package/dist/jsonld/JsonLd.d.mts +2 -0
- package/dist/jsonld/JsonLd.mjs +1 -0
- package/dist/jsonld/JsonLdError.d.mts +2 -0
- package/dist/jsonld/JsonLdError.mjs +1 -0
- package/dist/jsonld/index.d.mts +4 -0
- package/dist/jsonld/index.mjs +4 -0
- package/dist/lists-D-OpQ0Ir.mjs +77 -0
- package/dist/lists-D-OpQ0Ir.mjs.map +1 -0
- package/dist/loop-D5-gNx9K.mjs +21 -0
- package/dist/loop-D5-gNx9K.mjs.map +1 -0
- package/dist/loop-DZ2hXlr_.mjs +21 -0
- package/dist/loop-DZ2hXlr_.mjs.map +1 -0
- package/dist/n3/Isomorphism.d.mts +2 -0
- package/dist/n3/Isomorphism.mjs +1 -0
- package/dist/n3/Mapping.d.mts +2 -0
- package/dist/n3/Mapping.mjs +1 -0
- package/dist/n3/Model.d.mts +2 -0
- package/dist/n3/Model.mjs +1 -0
- package/dist/n3/N3.d.mts +2 -0
- package/dist/n3/N3.mjs +1 -0
- package/dist/n3/Reasoner.d.mts +2 -0
- package/dist/n3/Reasoner.mjs +2 -0
- package/dist/n3/Vocab.d.mts +2 -0
- package/dist/n3/Vocab.mjs +1 -0
- package/dist/n3/index.d.mts +7 -0
- package/dist/n3/index.mjs +7 -0
- package/dist/ntriples/Grammar.d.mts +2 -0
- package/dist/ntriples/Grammar.mjs +1 -0
- package/dist/ntriples/Lexical.d.mts +2 -0
- package/dist/ntriples/Lexical.mjs +1 -0
- package/dist/ntriples/NQuads.d.mts +2 -0
- package/dist/ntriples/NQuads.mjs +1 -0
- package/dist/ntriples/NTriples.d.mts +2 -0
- package/dist/ntriples/NTriples.mjs +1 -0
- package/dist/ntriples/index.d.mts +5 -0
- package/dist/ntriples/index.mjs +5 -0
- package/dist/rdfjson/RdfJson.d.mts +2 -0
- package/dist/rdfjson/RdfJson.mjs +1 -0
- package/dist/rdfjson/index.d.mts +2 -0
- package/dist/rdfjson/index.mjs +1 -0
- package/dist/rdfxml/RdfXml.d.mts +2 -0
- package/dist/rdfxml/RdfXml.mjs +1 -0
- package/dist/rdfxml/Xml.d.mts +2 -0
- package/dist/rdfxml/Xml.mjs +1 -0
- package/dist/rdfxml/index.d.mts +3 -0
- package/dist/rdfxml/index.mjs +3 -0
- package/dist/rolldown-runtime-D8jQpDG7.mjs +12 -0
- package/dist/serialize-96KBvKaf.mjs +1463 -0
- package/dist/serialize-96KBvKaf.mjs.map +1 -0
- package/dist/serialize-DsoXdM6n.d.mts +37 -0
- package/dist/shacl/Message.d.mts +2 -0
- package/dist/shacl/Message.mjs +1 -0
- package/dist/shacl/Path.d.mts +2 -0
- package/dist/shacl/Path.mjs +1 -0
- package/dist/shacl/Shapes.d.mts +2 -0
- package/dist/shacl/Shapes.mjs +1 -0
- package/dist/shacl/Sparql.d.mts +2 -0
- package/dist/shacl/Sparql.mjs +1 -0
- package/dist/shacl/ValidationReport.d.mts +2 -0
- package/dist/shacl/ValidationReport.mjs +1 -0
- package/dist/shacl/Validator.d.mts +2 -0
- package/dist/shacl/Validator.mjs +1 -0
- package/dist/shacl/Vocabulary.d.mts +2 -0
- package/dist/shacl/Vocabulary.mjs +1 -0
- package/dist/shacl/index.d.mts +9 -0
- package/dist/shacl/index.mjs +8 -0
- package/dist/shex/SemAct.d.mts +2 -0
- package/dist/shex/SemAct.mjs +1 -0
- package/dist/shex/ShExC.d.mts +2 -0
- package/dist/shex/ShExC.mjs +1 -0
- package/dist/shex/ShExError.d.mts +2 -0
- package/dist/shex/ShExError.mjs +1 -0
- package/dist/shex/ShExJ.d.mts +2 -0
- package/dist/shex/ShExJ.mjs +2 -0
- package/dist/shex/ShExR.d.mts +2 -0
- package/dist/shex/ShExR.mjs +1 -0
- package/dist/shex/ShapeMap.d.mts +2 -0
- package/dist/shex/ShapeMap.mjs +1 -0
- package/dist/shex/Structure.d.mts +2 -0
- package/dist/shex/Structure.mjs +2 -0
- package/dist/shex/Validator.d.mts +2 -0
- package/dist/shex/Validator.mjs +4 -0
- package/dist/shex/index.d.mts +9 -0
- package/dist/shex/index.mjs +9 -0
- package/dist/sparql/Algebra.d.mts +2 -0
- package/dist/sparql/Algebra.mjs +1 -0
- package/dist/sparql/Ast.d.mts +2 -0
- package/dist/sparql/Ast.mjs +1 -0
- package/dist/sparql/Bindings.d.mts +2 -0
- package/dist/sparql/Bindings.mjs +1 -0
- package/dist/sparql/ClientErrors.d.mts +2 -0
- package/dist/sparql/ClientErrors.mjs +1 -0
- package/dist/sparql/ClientFormats.d.mts +2 -0
- package/dist/sparql/ClientFormats.mjs +1 -0
- package/dist/sparql/Engine.d.mts +2 -0
- package/dist/sparql/Engine.mjs +1 -0
- package/dist/sparql/Errors.d.mts +2 -0
- package/dist/sparql/Errors.mjs +1 -0
- package/dist/sparql/Expression.d.mts +2 -0
- package/dist/sparql/Expression.mjs +1 -0
- package/dist/sparql/Federation.d.mts +2 -0
- package/dist/sparql/Federation.mjs +1 -0
- package/dist/sparql/Functions.d.mts +2 -0
- package/dist/sparql/Functions.mjs +1 -0
- package/dist/sparql/Generator.d.mts +2 -0
- package/dist/sparql/Generator.mjs +1 -0
- package/dist/sparql/GraphStore.d.mts +2 -0
- package/dist/sparql/GraphStore.mjs +1 -0
- package/dist/sparql/Optimizer.d.mts +2 -0
- package/dist/sparql/Optimizer.mjs +1 -0
- package/dist/sparql/Options.d.mts +2 -0
- package/dist/sparql/Options.mjs +1 -0
- package/dist/sparql/Parser.d.mts +2 -0
- package/dist/sparql/Parser.mjs +1 -0
- package/dist/sparql/Protocol.d.mts +2 -0
- package/dist/sparql/Protocol.mjs +1 -0
- package/dist/sparql/ProtocolErrors.d.mts +2 -0
- package/dist/sparql/ProtocolErrors.mjs +1 -0
- package/dist/sparql/QueryBuilder.d.mts +2 -0
- package/dist/sparql/QueryBuilder.mjs +1 -0
- package/dist/sparql/Results.d.mts +2 -0
- package/dist/sparql/Results.mjs +1 -0
- package/dist/sparql/ResultsStream.d.mts +2 -0
- package/dist/sparql/ResultsStream.mjs +1 -0
- package/dist/sparql/ServerFormats.d.mts +2 -0
- package/dist/sparql/ServerFormats.mjs +1 -0
- package/dist/sparql/ServiceDescription.d.mts +2 -0
- package/dist/sparql/ServiceDescription.mjs +1 -0
- package/dist/sparql/SparqlClient.d.mts +2 -0
- package/dist/sparql/SparqlClient.mjs +1 -0
- package/dist/sparql/SparqlServer.d.mts +2 -0
- package/dist/sparql/SparqlServer.mjs +1 -0
- package/dist/sparql/Store.d.mts +2 -0
- package/dist/sparql/Store.mjs +1 -0
- package/dist/sparql/TermSchema.d.mts +3 -0
- package/dist/sparql/TermSchema.mjs +2 -0
- package/dist/sparql/Testing.d.mts +2 -0
- package/dist/sparql/Testing.mjs +1 -0
- package/dist/sparql/Translate.d.mts +2 -0
- package/dist/sparql/Translate.mjs +1 -0
- package/dist/sparql/ai/Mcp.d.mts +2 -0
- package/dist/sparql/ai/Mcp.mjs +1 -0
- package/dist/sparql/ai/Tools.d.mts +2 -0
- package/dist/sparql/ai/Tools.mjs +1 -0
- package/dist/sparql/ai/index.d.mts +3 -0
- package/dist/sparql/ai/index.mjs +3 -0
- package/dist/sparql/index.d.mts +30 -0
- package/dist/sparql/index.mjs +29 -0
- package/dist/sparql/shacl/Evaluator.d.mts +2 -0
- package/dist/sparql/shacl/Evaluator.mjs +1 -0
- package/dist/sparql/shacl/Query.d.mts +2 -0
- package/dist/sparql/shacl/Query.mjs +1 -0
- package/dist/sparql/shacl/index.d.mts +3 -0
- package/dist/sparql/shacl/index.mjs +3 -0
- package/dist/sparql/sql/Dialect.d.mts +2 -0
- package/dist/sparql/sql/Dialect.mjs +1 -0
- package/dist/sparql/sql/SqlStore.d.mts +2 -0
- package/dist/sparql/sql/SqlStore.mjs +1 -0
- package/dist/sparql/sql/Translation.d.mts +2 -0
- package/dist/sparql/sql/Translation.mjs +1 -0
- package/dist/sparql/sql/index.d.mts +4 -0
- package/dist/sparql/sql/index.mjs +4 -0
- package/dist/stringMap-D5YIpYtR.mjs +38 -0
- package/dist/stringMap-D5YIpYtR.mjs.map +1 -0
- package/dist/tokens-C6BzeodQ.mjs +24 -0
- package/dist/tokens-C6BzeodQ.mjs.map +1 -0
- package/dist/turtle/Grammar.d.mts +3 -0
- package/dist/turtle/Grammar.mjs +3 -0
- package/dist/turtle/Manifest.d.mts +2 -0
- package/dist/turtle/Manifest.mjs +1 -0
- package/dist/turtle/TriG.d.mts +2 -0
- package/dist/turtle/TriG.mjs +1 -0
- package/dist/turtle/Turtle.d.mts +2 -0
- package/dist/turtle/Turtle.mjs +1 -0
- package/dist/turtle/index.d.mts +5 -0
- package/dist/turtle/index.mjs +5 -0
- package/dist/xmp/DublinCore.d.mts +2 -0
- package/dist/xmp/DublinCore.mjs +1 -0
- package/dist/xmp/Exif.d.mts +2 -0
- package/dist/xmp/Exif.mjs +1 -0
- package/dist/xmp/Extract.d.mts +2 -0
- package/dist/xmp/Extract.mjs +1 -0
- package/dist/xmp/Metadata.d.mts +2 -0
- package/dist/xmp/Metadata.mjs +1 -0
- package/dist/xmp/Namespaces.d.mts +2 -0
- package/dist/xmp/Namespaces.mjs +1 -0
- package/dist/xmp/Packet.d.mts +2 -0
- package/dist/xmp/Packet.mjs +1 -0
- package/dist/xmp/Pdf.d.mts +2 -0
- package/dist/xmp/Pdf.mjs +1 -0
- package/dist/xmp/PdfA.d.mts +2 -0
- package/dist/xmp/PdfA.mjs +1 -0
- package/dist/xmp/Photoshop.d.mts +2 -0
- package/dist/xmp/Photoshop.mjs +1 -0
- package/dist/xmp/Tiff.d.mts +2 -0
- package/dist/xmp/Tiff.mjs +1 -0
- package/dist/xmp/Xmp.d.mts +2 -0
- package/dist/xmp/Xmp.mjs +3 -0
- package/dist/xmp/XmpBasic.d.mts +2 -0
- package/dist/xmp/XmpBasic.mjs +1 -0
- package/dist/xmp/XmpMM.d.mts +2 -0
- package/dist/xmp/XmpMM.mjs +1 -0
- package/dist/xmp/XmpRights.d.mts +2 -0
- package/dist/xmp/XmpRights.mjs +1 -0
- package/dist/xmp/index.d.mts +15 -0
- package/dist/xmp/index.mjs +15 -0
- package/package.json +187 -3
- package/src/Dataset.ts +1085 -0
- package/src/Iri.ts +322 -0
- package/src/Isomorphism.ts +319 -0
- package/src/LanguageTag.ts +98 -0
- package/src/Namespace.ts +100 -0
- package/src/PrefixMap.ts +117 -0
- package/src/RdfJs.ts +146 -0
- package/src/Rdfs.ts +241 -0
- package/src/Reification.ts +103 -0
- package/src/Resource.ts +873 -0
- package/src/Serialization.ts +775 -0
- package/src/Term.ts +1300 -0
- package/src/TermCodec.ts +505 -0
- package/src/TermJson.ts +313 -0
- package/src/Vocab.ts +161 -0
- package/src/Xsd.ts +573 -0
- package/src/csvw/Csv2Json.ts +265 -0
- package/src/csvw/Csv2Rdf.ts +268 -0
- package/src/csvw/Datatype.ts +589 -0
- package/src/csvw/Metadata.ts +1523 -0
- package/src/csvw/Processor.ts +276 -0
- package/src/csvw/Report.ts +135 -0
- package/src/csvw/Table.ts +759 -0
- package/src/csvw/index.ts +22 -0
- package/src/csvw/internal/dateFormat.ts +202 -0
- package/src/csvw/internal/json.ts +104 -0
- package/src/csvw/internal/numberFormat.ts +369 -0
- package/src/csvw/internal/object.ts +23 -0
- package/src/csvw/internal/uriTemplate.ts +130 -0
- package/src/csvw/internal/url.ts +93 -0
- package/src/csvw/internal/vocab.ts +282 -0
- package/src/index.ts +40 -0
- package/src/internal/arbitrary.ts +148 -0
- package/src/internal/loop.ts +24 -0
- package/src/internal/pending.ts +20 -0
- package/src/internal/textDecoder.ts +183 -0
- package/src/jsonld/DocumentLoader.ts +512 -0
- package/src/jsonld/JsonLd.ts +847 -0
- package/src/jsonld/JsonLdError.ts +105 -0
- package/src/jsonld/index.ts +13 -0
- package/src/jsonld/internal/compact.ts +852 -0
- package/src/jsonld/internal/context.ts +781 -0
- package/src/jsonld/internal/expand.ts +614 -0
- package/src/jsonld/internal/flatten.ts +243 -0
- package/src/jsonld/internal/frame.ts +559 -0
- package/src/jsonld/internal/iri.ts +52 -0
- package/src/jsonld/internal/json.ts +19 -0
- package/src/jsonld/internal/linkHeader.ts +60 -0
- package/src/jsonld/internal/rdf.ts +481 -0
- package/src/jsonld/internal/util.ts +367 -0
- package/src/n3/Isomorphism.ts +476 -0
- package/src/n3/Mapping.ts +332 -0
- package/src/n3/Model.ts +696 -0
- package/src/n3/N3.ts +237 -0
- package/src/n3/Reasoner.ts +568 -0
- package/src/n3/Vocab.ts +111 -0
- package/src/n3/index.ts +21 -0
- package/src/n3/internal/builtins.ts +668 -0
- package/src/n3/internal/guards.ts +23 -0
- package/src/n3/internal/lists.ts +106 -0
- package/src/n3/internal/loop.ts +28 -0
- package/src/n3/internal/parser.ts +1032 -0
- package/src/n3/internal/writer.ts +344 -0
- package/src/ntriples/Grammar.ts +317 -0
- package/src/ntriples/Lexical.ts +321 -0
- package/src/ntriples/NQuads.ts +140 -0
- package/src/ntriples/NTriples.ts +143 -0
- package/src/ntriples/index.ts +14 -0
- package/src/ntriples/internal/codec.ts +229 -0
- package/src/ntriples/internal/lineParser.ts +326 -0
- package/src/ntriples/internal/loop.ts +14 -0
- package/src/rdfjson/RdfJson.ts +806 -0
- package/src/rdfjson/index.ts +9 -0
- package/src/rdfjson/internal/json.ts +19 -0
- package/src/rdfxml/RdfXml.ts +1408 -0
- package/src/rdfxml/Xml.ts +419 -0
- package/src/rdfxml/index.ts +11 -0
- package/src/rdfxml/internal/chars.ts +73 -0
- package/src/rdfxml/internal/loop.ts +24 -0
- package/src/rdfxml/internal/parser.ts +1265 -0
- package/src/shacl/Message.ts +102 -0
- package/src/shacl/Path.ts +483 -0
- package/src/shacl/Shapes.ts +913 -0
- package/src/shacl/Sparql.ts +128 -0
- package/src/shacl/ValidationReport.ts +438 -0
- package/src/shacl/Validator.ts +1156 -0
- package/src/shacl/Vocabulary.ts +180 -0
- package/src/shacl/index.ts +22 -0
- package/src/shacl/internal/compare.ts +128 -0
- package/src/shacl/internal/regex.ts +56 -0
- package/src/shex/SemAct.ts +197 -0
- package/src/shex/ShExC.ts +415 -0
- package/src/shex/ShExError.ts +71 -0
- package/src/shex/ShExJ.ts +893 -0
- package/src/shex/ShExR.ts +640 -0
- package/src/shex/ShapeMap.ts +385 -0
- package/src/shex/Structure.ts +467 -0
- package/src/shex/Validator.ts +395 -0
- package/src/shex/index.ts +24 -0
- package/src/shex/internal/engine.ts +682 -0
- package/src/shex/internal/iterate.ts +14 -0
- package/src/shex/internal/json.ts +12 -0
- package/src/shex/internal/lexer.ts +56 -0
- package/src/shex/internal/nodeConstraint.ts +368 -0
- package/src/shex/internal/shexcLexer.ts +387 -0
- package/src/shex/internal/shexcParser.ts +1312 -0
- package/src/shex/internal/tokens.ts +41 -0
- package/src/shex/internal/xpathRegex.ts +290 -0
- package/src/sparql/Algebra.ts +914 -0
- package/src/sparql/Ast.ts +1344 -0
- package/src/sparql/Bindings.ts +272 -0
- package/src/sparql/ClientErrors.ts +156 -0
- package/src/sparql/ClientFormats.ts +70 -0
- package/src/sparql/Engine.ts +699 -0
- package/src/sparql/Errors.ts +30 -0
- package/src/sparql/Expression.ts +360 -0
- package/src/sparql/Federation.ts +187 -0
- package/src/sparql/Functions.ts +689 -0
- package/src/sparql/Generator.ts +426 -0
- package/src/sparql/GraphStore.ts +341 -0
- package/src/sparql/Optimizer.ts +230 -0
- package/src/sparql/Options.ts +191 -0
- package/src/sparql/Parser.ts +173 -0
- package/src/sparql/Protocol.ts +342 -0
- package/src/sparql/ProtocolErrors.ts +113 -0
- package/src/sparql/QueryBuilder.ts +953 -0
- package/src/sparql/Results.ts +844 -0
- package/src/sparql/ResultsStream.ts +771 -0
- package/src/sparql/ServerFormats.ts +75 -0
- package/src/sparql/ServiceDescription.ts +130 -0
- package/src/sparql/SparqlClient.ts +947 -0
- package/src/sparql/SparqlServer.ts +528 -0
- package/src/sparql/Store.ts +311 -0
- package/src/sparql/TermSchema.ts +20 -0
- package/src/sparql/Testing.ts +114 -0
- package/src/sparql/Translate.ts +407 -0
- package/src/sparql/ai/Mcp.ts +43 -0
- package/src/sparql/ai/Tools.ts +481 -0
- package/src/sparql/ai/index.ts +11 -0
- package/src/sparql/index.ts +64 -0
- package/src/sparql/internal/evaluator.ts +947 -0
- package/src/sparql/internal/hash.ts +418 -0
- package/src/sparql/internal/json.ts +12 -0
- package/src/sparql/internal/lexer.ts +488 -0
- package/src/sparql/internal/loop.ts +24 -0
- package/src/sparql/internal/parser.ts +2215 -0
- package/src/sparql/internal/prefetch.ts +46 -0
- package/src/sparql/internal/stringMap.ts +39 -0
- package/src/sparql/internal/textResults.ts +226 -0
- package/src/sparql/internal/values.ts +550 -0
- package/src/sparql/shacl/Evaluator.ts +478 -0
- package/src/sparql/shacl/Query.ts +574 -0
- package/src/sparql/shacl/index.ts +12 -0
- package/src/sparql/sql/Dialect.ts +246 -0
- package/src/sparql/sql/SqlStore.ts +1080 -0
- package/src/sparql/sql/Translation.ts +1898 -0
- package/src/sparql/sql/index.ts +17 -0
- package/src/sparql/sql/internal/encoding.ts +313 -0
- package/src/turtle/Grammar.ts +286 -0
- package/src/turtle/Manifest.ts +215 -0
- package/src/turtle/TriG.ts +158 -0
- package/src/turtle/Turtle.ts +166 -0
- package/src/turtle/index.ts +14 -0
- package/src/turtle/internal/loop.ts +23 -0
- package/src/turtle/internal/parse.ts +112 -0
- package/src/turtle/internal/parser.ts +1303 -0
- package/src/turtle/internal/serialize.ts +79 -0
- package/src/turtle/internal/streamWriter.ts +128 -0
- package/src/turtle/internal/writer.ts +898 -0
- package/src/xmp/DublinCore.ts +147 -0
- package/src/xmp/Exif.ts +109 -0
- package/src/xmp/Extract.ts +351 -0
- package/src/xmp/Metadata.ts +703 -0
- package/src/xmp/Namespaces.ts +228 -0
- package/src/xmp/Packet.ts +297 -0
- package/src/xmp/Pdf.ts +99 -0
- package/src/xmp/PdfA.ts +280 -0
- package/src/xmp/Photoshop.ts +275 -0
- package/src/xmp/Tiff.ts +196 -0
- package/src/xmp/Xmp.ts +430 -0
- package/src/xmp/XmpBasic.ts +90 -0
- package/src/xmp/XmpMM.ts +82 -0
- package/src/xmp/XmpRights.ts +83 -0
- package/src/xmp/index.ts +36 -0
- package/src/xmp/internal/accessors.ts +72 -0
- package/src/xmp/internal/xml.ts +63 -0
|
@@ -0,0 +1,1463 @@
|
|
|
1
|
+
import { A as escapeString, B as isNamedNode, I as isGround, K as isTriple, N as isBlankNode, O as defaultGraph, P as isDefaultGraph, T as blankNode$1, Y as literal, c as NamedNode, d as Quad, k as escapeIri, o as Literal, t as BlankNode, y as Triple, z as isLiteral } from "./Term-CFLG1qu4.mjs";
|
|
2
|
+
import { m as fromIterable } from "./Dataset-BlmlcI7J.mjs";
|
|
3
|
+
import { i as rdf, n as commonPrefixes, o as xsd } from "./Vocab-DceKywpq.mjs";
|
|
4
|
+
import { l as resolve, s as relativize } from "./Iri-Cr92gsQV.mjs";
|
|
5
|
+
import { i as relabel } from "./Isomorphism-BmqxhKyJ.mjs";
|
|
6
|
+
import { s as make } from "./PrefixMap-BHFPDLO-.mjs";
|
|
7
|
+
import { C as withParseSpan, T as withStreamSpan, n as RdfParseError, o as freshBlankNodePrefix, r as RdfSerializeError, w as withSerializeSpan } from "./Serialization-DP9H5bYQ.mjs";
|
|
8
|
+
import { d as iriRef, h as pnCharsBase, i as blankNodeLabel, m as pnChars, r as alphanumeric } from "./Grammar-mQ8CgE1M.mjs";
|
|
9
|
+
import { a as double, d as pnPrefix, i as decimal, m as stringLiteral, p as skip$1, s as integer, u as pnLocal } from "./Grammar-CPlSxGH6.mjs";
|
|
10
|
+
import { _ as makeLiteral, c as isAbsoluteIri, d as isHex, f as isIriChar, g as isWritableIri, h as isPnCharsU, i as decodeUchar, m as isPnCharsBase, n as blankNodeLabel$1, p as isPnChars, r as decodeEchar, u as isDigit, v as parseLanguageTag } from "./Lexical-Cg0JHrf6.mjs";
|
|
11
|
+
import * as Arr from "effect/Array";
|
|
12
|
+
import * as Iterable from "effect/Iterable";
|
|
13
|
+
import * as MutableHashMap from "effect/MutableHashMap";
|
|
14
|
+
import * as MutableHashSet from "effect/MutableHashSet";
|
|
15
|
+
import * as Option from "effect/Option";
|
|
16
|
+
import * as Predicate from "effect/Predicate";
|
|
17
|
+
import * as Effect from "effect/Effect";
|
|
18
|
+
import * as Order from "effect/Order";
|
|
19
|
+
import * as Str from "effect/String";
|
|
20
|
+
import * as Record from "effect/Record";
|
|
21
|
+
import * as Stream from "effect/Stream";
|
|
22
|
+
import * as Result from "effect/Result";
|
|
23
|
+
import * as Ascii from "@thomasfosterau/effect-parse/Ascii";
|
|
24
|
+
import * as Compiler from "@thomasfosterau/effect-parse/Compiler";
|
|
25
|
+
import * as Parser from "@thomasfosterau/effect-parse/Parser";
|
|
26
|
+
import * as Token from "@thomasfosterau/effect-parse/Token";
|
|
27
|
+
// src/turtle/internal/loop.ts
|
|
28
|
+
/**
|
|
29
|
+
* A loop as a function, for the scans that step a cursor until a condition
|
|
30
|
+
* holds (decoding an escape, walking a list, counting line breaks).
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
const BLOCK = 1024;
|
|
35
|
+
/** `0 … BLOCK - 1`: the steps of one block run as an array scan, which engines optimise well. */
|
|
36
|
+
const offsets = Array.from({ length: BLOCK }, (_, i) => i);
|
|
37
|
+
/** The first step of each block after the first: `BLOCK, 2 * BLOCK, …`. */
|
|
38
|
+
const blocks = Iterable.makeBy((b) => (b + 1) * BLOCK);
|
|
39
|
+
/** Calls `step` with 0, 1, 2, … until it returns `false`. */
|
|
40
|
+
const loop = (step) => {
|
|
41
|
+
if (offsets.every((i) => step(i))) Iterable.some(blocks, (base) => offsets.some((i) => !step(base + i)));
|
|
42
|
+
};
|
|
43
|
+
// src/turtle/internal/parser.ts
|
|
44
|
+
/**
|
|
45
|
+
* The Turtle and TriG (RDF 1.2) parser: a compiled
|
|
46
|
+
* `@thomasfosterau/effect-parse` grammar over the input string, built on the
|
|
47
|
+
* terminals of `Grammar.ts`, that emits quads as it reads.
|
|
48
|
+
*
|
|
49
|
+
* What depends on the document so far (prefixes, the base IRI, blank node
|
|
50
|
+
* labels and counters, the current graph) lives in a per-parser `Builder`
|
|
51
|
+
* that the grammar's callbacks update, as the hand-written parser it replaces
|
|
52
|
+
* did. Errors are thrown out of the grammar (as a `Stop` at an offset) at the
|
|
53
|
+
* points, and with the messages, of that parser.
|
|
54
|
+
*
|
|
55
|
+
* Input can be fed incrementally. Each run parses as many statements as the
|
|
56
|
+
* buffered text holds; a statement that ends too close to the end of the
|
|
57
|
+
* buffer to be sure of (or fails there) is rolled back and retried with more
|
|
58
|
+
* text, and a statement that fails before the input is complete is re-read in
|
|
59
|
+
* partial mode to tell a real error from a statement that is merely cut off.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
/** @internal */
|
|
64
|
+
var SyntaxFailure = class extends Error {
|
|
65
|
+
line;
|
|
66
|
+
column;
|
|
67
|
+
constructor(message, line, column) {
|
|
68
|
+
super(message);
|
|
69
|
+
this.line = line;
|
|
70
|
+
this.column = column;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/** An error at an offset of the text being parsed, thrown out of the grammar. */
|
|
74
|
+
var Stop = class {
|
|
75
|
+
message;
|
|
76
|
+
pos;
|
|
77
|
+
constructor(message, pos) {
|
|
78
|
+
this.message = message;
|
|
79
|
+
this.pos = pos;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* How far past the end of a statement, and past any dots there, the grammar
|
|
84
|
+
* may look (`.%41`, `1.e+5`): a statement ending closer than this to the end
|
|
85
|
+
* of incomplete input is retried once more text has arrived. (A run of dots
|
|
86
|
+
* may continue a name, as in `ex:a...b`, however long it is.)
|
|
87
|
+
*/
|
|
88
|
+
const MARGIN = 3;
|
|
89
|
+
const C_DOT = 46;
|
|
90
|
+
const C_BACKSLASH = 92;
|
|
91
|
+
const C_PERCENT = 37;
|
|
92
|
+
const C_GT = 62;
|
|
93
|
+
/** A run of dots, matched where it starts. */
|
|
94
|
+
const DOTS = /\.*/y;
|
|
95
|
+
/** The offset after any dots at `pos`. */
|
|
96
|
+
const skipDots = (input, pos) => {
|
|
97
|
+
if (input.charCodeAt(pos) !== C_DOT) return pos;
|
|
98
|
+
DOTS.lastIndex = pos;
|
|
99
|
+
DOTS.test(input);
|
|
100
|
+
return DOTS.lastIndex;
|
|
101
|
+
};
|
|
102
|
+
/** The subject being described, with the predicate, object and reifier in progress. */
|
|
103
|
+
var Frame = class {
|
|
104
|
+
subject = rdf.nil;
|
|
105
|
+
predicate = rdf.nil;
|
|
106
|
+
object = rdf.nil;
|
|
107
|
+
reifier = Option.none();
|
|
108
|
+
/** The triple of the current object, once built for a reifier. */
|
|
109
|
+
triple = Option.none();
|
|
110
|
+
};
|
|
111
|
+
const noReifier = Option.none();
|
|
112
|
+
const noTriple = Option.none();
|
|
113
|
+
var Builder = class {
|
|
114
|
+
options;
|
|
115
|
+
prefixes = MutableHashMap.empty();
|
|
116
|
+
base;
|
|
117
|
+
out = [];
|
|
118
|
+
labels = MutableHashMap.empty();
|
|
119
|
+
counter = 0;
|
|
120
|
+
graph;
|
|
121
|
+
inGraph = false;
|
|
122
|
+
/** Whether the input is complete, and the text being parsed. */
|
|
123
|
+
final = true;
|
|
124
|
+
input = "";
|
|
125
|
+
frames = [];
|
|
126
|
+
depth = -1;
|
|
127
|
+
/** A node read before it is known what it is (a TriG subject or graph name). */
|
|
128
|
+
pending = rdf.nil;
|
|
129
|
+
/** The state at the start of the current statement, to roll back to. */
|
|
130
|
+
open = false;
|
|
131
|
+
snapPos = 0;
|
|
132
|
+
snapOut = 0;
|
|
133
|
+
snapCounter = 0;
|
|
134
|
+
snapGraph;
|
|
135
|
+
snapInGraph = false;
|
|
136
|
+
snapBase = Option.none();
|
|
137
|
+
/** The prefix the statement bound, with its previous binding. */
|
|
138
|
+
snapPrefix = Option.none();
|
|
139
|
+
/** Registers for the terms being read (none of them nests). */
|
|
140
|
+
iriStart = 0;
|
|
141
|
+
iriEnd = 0;
|
|
142
|
+
nameStart = 0;
|
|
143
|
+
prefix = "";
|
|
144
|
+
stringStart = 0;
|
|
145
|
+
stringEnd = 0;
|
|
146
|
+
tagStart = 0;
|
|
147
|
+
literalStart = 0;
|
|
148
|
+
literalValue = "";
|
|
149
|
+
/** Where the last complete statement ended. */
|
|
150
|
+
lastEnd = 0;
|
|
151
|
+
/** The state at the start of the run, for a re-run. */
|
|
152
|
+
runOut = 0;
|
|
153
|
+
runCounter = 0;
|
|
154
|
+
runGraph;
|
|
155
|
+
runInGraph = false;
|
|
156
|
+
runBase = Option.none();
|
|
157
|
+
/** The prefixes set during the run, with their previous values. */
|
|
158
|
+
runPrefixes = [];
|
|
159
|
+
constructor(options) {
|
|
160
|
+
this.options = options;
|
|
161
|
+
this.base = options.baseIri;
|
|
162
|
+
this.graph = options.graph;
|
|
163
|
+
this.snapGraph = options.graph;
|
|
164
|
+
this.runGraph = options.graph;
|
|
165
|
+
}
|
|
166
|
+
/** Records the state at the start of a run. */
|
|
167
|
+
beginRun() {
|
|
168
|
+
this.open = false;
|
|
169
|
+
this.lastEnd = 0;
|
|
170
|
+
this.runOut = this.out.length;
|
|
171
|
+
this.runCounter = this.counter;
|
|
172
|
+
this.runGraph = this.graph;
|
|
173
|
+
this.runInGraph = this.inGraph;
|
|
174
|
+
this.runBase = this.base;
|
|
175
|
+
this.runPrefixes.length = 0;
|
|
176
|
+
}
|
|
177
|
+
/** Returns to the state at the start of the run (for the re-run of a failed one). */
|
|
178
|
+
restartRun() {
|
|
179
|
+
this.open = false;
|
|
180
|
+
this.lastEnd = 0;
|
|
181
|
+
this.depth = -1;
|
|
182
|
+
this.out.length = this.runOut;
|
|
183
|
+
this.counter = this.runCounter;
|
|
184
|
+
this.graph = this.runGraph;
|
|
185
|
+
this.inGraph = this.runInGraph;
|
|
186
|
+
this.base = this.runBase;
|
|
187
|
+
Arr.forEach(Arr.reverse(this.runPrefixes), (binding) => this.restorePrefix(binding));
|
|
188
|
+
this.runPrefixes.length = 0;
|
|
189
|
+
}
|
|
190
|
+
restorePrefix([prefix, previous]) {
|
|
191
|
+
if (Option.isSome(previous)) MutableHashMap.set(this.prefixes, prefix, previous.value);
|
|
192
|
+
else MutableHashMap.remove(this.prefixes, prefix);
|
|
193
|
+
}
|
|
194
|
+
frame() {
|
|
195
|
+
return this.frames[this.depth] ?? new Frame();
|
|
196
|
+
}
|
|
197
|
+
push(subject) {
|
|
198
|
+
const frame = this.frames[++this.depth] ??= new Frame();
|
|
199
|
+
frame.subject = subject;
|
|
200
|
+
frame.reifier = noReifier;
|
|
201
|
+
frame.triple = noTriple;
|
|
202
|
+
}
|
|
203
|
+
emit(s, p, o) {
|
|
204
|
+
this.out.push(new Quad(s, p, o, this.graph));
|
|
205
|
+
}
|
|
206
|
+
fresh() {
|
|
207
|
+
return new BlankNode(`${this.options.blankNodePrefix}_${(this.counter++).toString(36)}`);
|
|
208
|
+
}
|
|
209
|
+
snapshot(pos) {
|
|
210
|
+
this.open = true;
|
|
211
|
+
this.depth = -1;
|
|
212
|
+
this.snapPos = pos;
|
|
213
|
+
this.snapOut = this.out.length;
|
|
214
|
+
this.snapCounter = this.counter;
|
|
215
|
+
this.snapGraph = this.graph;
|
|
216
|
+
this.snapInGraph = this.inGraph;
|
|
217
|
+
this.snapBase = this.base;
|
|
218
|
+
this.snapPrefix = Option.none();
|
|
219
|
+
}
|
|
220
|
+
/** Undoes the statement in progress. */
|
|
221
|
+
rollback() {
|
|
222
|
+
if (!this.open) return;
|
|
223
|
+
this.out.length = this.snapOut;
|
|
224
|
+
this.counter = this.snapCounter;
|
|
225
|
+
this.graph = this.snapGraph;
|
|
226
|
+
this.inGraph = this.snapInGraph;
|
|
227
|
+
this.base = this.snapBase;
|
|
228
|
+
if (Option.isSome(this.snapPrefix)) {
|
|
229
|
+
this.restorePrefix(this.snapPrefix.value);
|
|
230
|
+
this.snapPrefix = Option.none();
|
|
231
|
+
}
|
|
232
|
+
this.depth = -1;
|
|
233
|
+
}
|
|
234
|
+
setPrefix(prefix, iri) {
|
|
235
|
+
const binding = [prefix, MutableHashMap.get(this.prefixes, prefix)];
|
|
236
|
+
if (Option.isNone(this.snapPrefix)) this.snapPrefix = Option.some(binding);
|
|
237
|
+
this.runPrefixes.push(binding);
|
|
238
|
+
MutableHashMap.set(this.prefixes, prefix, iri);
|
|
239
|
+
}
|
|
240
|
+
openGraph(graph) {
|
|
241
|
+
this.inGraph = true;
|
|
242
|
+
this.graph = graph;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
/** The builder of the parser running the grammar. */
|
|
246
|
+
let b = new Builder({
|
|
247
|
+
trig: false,
|
|
248
|
+
baseIri: Option.none(),
|
|
249
|
+
blankNodePrefix: "",
|
|
250
|
+
graph: defaultGraph
|
|
251
|
+
});
|
|
252
|
+
const lit = Token.literal;
|
|
253
|
+
const skip = skip$1;
|
|
254
|
+
/** Runs `f` at the current offset, consuming nothing (never skipped by the compiler). */
|
|
255
|
+
const act = (f) => Parser.tap(Parser.location, f);
|
|
256
|
+
/** Throws `message` at the current offset. */
|
|
257
|
+
const failHere = (message) => Parser.make((state) => {
|
|
258
|
+
throw new Stop(message, state.pos);
|
|
259
|
+
});
|
|
260
|
+
/** Throws the error `diagnose` finds at the current offset. */
|
|
261
|
+
const failWith = (diagnose) => Parser.make((state) => {
|
|
262
|
+
throw diagnose(state.input, state.pos);
|
|
263
|
+
});
|
|
264
|
+
const at = (s) => Parser.peek(lit(s));
|
|
265
|
+
const nameChar = Token.oneOf([pnChars, ":"]);
|
|
266
|
+
const notName = Parser.not(nameChar);
|
|
267
|
+
/** A case-insensitive keyword followed by a character that cannot continue a name. */
|
|
268
|
+
const keyword = (word) => Parser.terminated(Ascii.caseless(word), notName);
|
|
269
|
+
/** An `@` keyword, not followed by a letter, digit or `-`. */
|
|
270
|
+
const atKeyword = (word) => Parser.terminated(lit(word), Parser.not(Token.oneOf([alphanumeric, "-"])));
|
|
271
|
+
/** `.` or the error "Expected `what`". */
|
|
272
|
+
const expectDot = (what) => Parser.alt(lit("."), failHere(`Expected ${what}`));
|
|
273
|
+
const nameStart = Parser.peek(Parser.alt(lit(":"), Token.oneOf(pnCharsBase)));
|
|
274
|
+
const isDecodeError = Predicate.isTagged("Error");
|
|
275
|
+
/**
|
|
276
|
+
* Scans from `start` with `step`, which returns the next offset, or the
|
|
277
|
+
* error found (`Some`) or the end of the term (`None`) to stop.
|
|
278
|
+
*/
|
|
279
|
+
const scan = (start, step) => {
|
|
280
|
+
let i = start;
|
|
281
|
+
let error = Option.none();
|
|
282
|
+
loop(() => {
|
|
283
|
+
const next = step(i);
|
|
284
|
+
if (Predicate.isNumber(next)) {
|
|
285
|
+
i = next;
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
error = next;
|
|
289
|
+
return false;
|
|
290
|
+
});
|
|
291
|
+
return error;
|
|
292
|
+
};
|
|
293
|
+
const fail = (message, pos) => Option.some(new Stop(message, pos));
|
|
294
|
+
/** The error in the IRI at `start`, or `None`; `end` bounds an IRI that matched. */
|
|
295
|
+
const iriError = (input, start, end = input.length) => scan(start + 1, (i) => {
|
|
296
|
+
if (i >= end) return end === input.length ? fail("Unterminated IRI", start) : Option.none();
|
|
297
|
+
const c = input.charCodeAt(i);
|
|
298
|
+
if (c === C_GT) return Option.none();
|
|
299
|
+
if (c === C_BACKSLASH) {
|
|
300
|
+
const decoded = decodeUchar(input, i);
|
|
301
|
+
if (isDecodeError(decoded)) return fail(decoded.message, i);
|
|
302
|
+
if (!isIriChar(decoded.value.codePointAt(0) ?? 0)) return fail("Escaped character is not allowed in an IRI", i);
|
|
303
|
+
return i + decoded.length;
|
|
304
|
+
}
|
|
305
|
+
if (!isIriChar(c)) return fail("Invalid character in IRI", i);
|
|
306
|
+
return i + 1;
|
|
307
|
+
});
|
|
308
|
+
/** The error in the string at `start`, or `None`; `end` bounds a string that matched. */
|
|
309
|
+
const stringError = (input, start, end = input.length) => {
|
|
310
|
+
const q = input.charCodeAt(start);
|
|
311
|
+
const long = input.charCodeAt(start + 1) === q && input.charCodeAt(start + 2) === q;
|
|
312
|
+
if (!long && input.charCodeAt(start + 1) === q) return Option.none();
|
|
313
|
+
return scan(start + (long ? 3 : 1), (i) => {
|
|
314
|
+
if (i >= end) return end === input.length ? fail("Unterminated string literal", start) : Option.none();
|
|
315
|
+
const c = input.charCodeAt(i);
|
|
316
|
+
if (c === q) {
|
|
317
|
+
if (!long) return Option.none();
|
|
318
|
+
if (input.charCodeAt(i + 1) === q && input.charCodeAt(i + 2) === q) return Option.none();
|
|
319
|
+
return i + 1;
|
|
320
|
+
}
|
|
321
|
+
if (c === C_BACKSLASH) {
|
|
322
|
+
if (decodeEchar(input.charCodeAt(i + 1)) !== void 0) return i + 2;
|
|
323
|
+
const decoded = decodeUchar(input, i);
|
|
324
|
+
if (isDecodeError(decoded)) return fail(decoded.message, i);
|
|
325
|
+
return i + decoded.length;
|
|
326
|
+
}
|
|
327
|
+
if (!long && (c === 10 || c === 13)) return fail("Line break in string literal", i);
|
|
328
|
+
return i + 1;
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
const diagnosis = (find, message) => (input, pos) => Option.getOrElse(find(input, pos), () => new Stop(message, pos));
|
|
332
|
+
/** `IRIREF` (at a `<`), resolved against the base. */
|
|
333
|
+
const iri = Parser.preceded(act((pos) => {
|
|
334
|
+
b.iriStart = pos;
|
|
335
|
+
}), Parser.terminated(Parser.alt(Parser.backtrack(iriRef), failWith(diagnosis(iriError, "Invalid IRI"))), act((pos) => {
|
|
336
|
+
b.iriEnd = pos;
|
|
337
|
+
}))).pipe(Parser.map((value) => {
|
|
338
|
+
const start = b.iriStart;
|
|
339
|
+
if (b.iriEnd - start - 2 !== value.length) {
|
|
340
|
+
const error = iriError(b.input, start, b.iriEnd);
|
|
341
|
+
if (Option.isSome(error)) throw error.value;
|
|
342
|
+
}
|
|
343
|
+
if (Option.isNone(b.base)) {
|
|
344
|
+
if (!isAbsoluteIri(value)) throw new Stop(`Relative IRI <${value}> cannot be resolved without a base IRI`, start);
|
|
345
|
+
return new NamedNode(value);
|
|
346
|
+
}
|
|
347
|
+
return new NamedNode(resolve(value, b.base.value));
|
|
348
|
+
}));
|
|
349
|
+
/** Fails when a prefix name is followed by a dot (which `PN_PREFIX` cannot end with). */
|
|
350
|
+
const noTrailingDot = Parser.make((state) => {
|
|
351
|
+
if (state.input.charCodeAt(state.pos) === C_DOT) throw new Stop("A prefix name must not end with \".\"", state.pos - b.prefix.length);
|
|
352
|
+
});
|
|
353
|
+
/** `PN_PREFIX` (possibly empty), before the colon. */
|
|
354
|
+
const prefixLabel = Parser.alt(Parser.terminated(Parser.tap(pnPrefix, (prefix) => {
|
|
355
|
+
b.prefix = prefix;
|
|
356
|
+
}), noTrailingDot), Parser.preceded(at(":"), Parser.succeed("")), failHere("Invalid prefix name"));
|
|
357
|
+
/** Fails on the escapes that end a local name early: `%` or `\` (after any dots). */
|
|
358
|
+
const localTail = Parser.make((state) => {
|
|
359
|
+
const input = state.input;
|
|
360
|
+
const i = skipDots(input, state.pos);
|
|
361
|
+
const c = input.charCodeAt(i);
|
|
362
|
+
if (c === C_PERCENT) throw new Stop("Invalid percent escape", i);
|
|
363
|
+
if (c === C_BACKSLASH) throw new Stop("Invalid escape in local name", i);
|
|
364
|
+
});
|
|
365
|
+
const prefixedName = Parser.preceded(Parser.seq(act((pos) => {
|
|
366
|
+
b.nameStart = pos;
|
|
367
|
+
}), Parser.tap(prefixLabel, (prefix) => {
|
|
368
|
+
b.prefix = prefix;
|
|
369
|
+
})), Parser.alt(Parser.preceded(lit(":"), Parser.terminated(Parser.alt(pnLocal, Parser.succeed("")), localTail)).pipe(Parser.map((local) => {
|
|
370
|
+
const ns = MutableHashMap.get(b.prefixes, b.prefix);
|
|
371
|
+
if (Option.isNone(ns)) throw new Stop(`Undefined prefix "${b.prefix}:"`, b.nameStart);
|
|
372
|
+
return new NamedNode(ns.value + local);
|
|
373
|
+
})), Parser.make(() => {
|
|
374
|
+
throw new Stop("Expected a prefixed name", b.nameStart);
|
|
375
|
+
})));
|
|
376
|
+
const blankNode = Parser.alt(blankNodeLabel, Parser.preceded(lit("_:"), failHere("Invalid blank node label"))).pipe(Parser.map((label) => {
|
|
377
|
+
const found = MutableHashMap.get(b.labels, label);
|
|
378
|
+
if (Option.isSome(found)) return found.value;
|
|
379
|
+
const node = new BlankNode(b.options.blankNodePrefix + (label.startsWith("_") ? `_${label}` : label));
|
|
380
|
+
MutableHashMap.set(b.labels, label, node);
|
|
381
|
+
return node;
|
|
382
|
+
}));
|
|
383
|
+
/** An IRI or a blank node label (no anonymous nodes). */
|
|
384
|
+
const resource = Parser.alt(Parser.preceded(at("<<"), failHere("Unexpected triple")), Parser.preceded(at("<"), iri), Parser.preceded(at("_:"), blankNode), prefixedName);
|
|
385
|
+
/** Any of the four string forms (at a quote), returning the value. */
|
|
386
|
+
const string = Parser.preceded(act((pos) => {
|
|
387
|
+
b.stringStart = pos;
|
|
388
|
+
}), Parser.terminated(Parser.alt(Parser.backtrack(stringLiteral), failWith(diagnosis(stringError, "Invalid string literal"))), act((pos) => {
|
|
389
|
+
b.stringEnd = pos;
|
|
390
|
+
}))).pipe(Parser.map((value) => {
|
|
391
|
+
const input = b.input;
|
|
392
|
+
const start = b.stringStart;
|
|
393
|
+
const q = input.charCodeAt(start);
|
|
394
|
+
const quotes = input.charCodeAt(start + 1) === q && input.charCodeAt(start + 2) === q ? 6 : 2;
|
|
395
|
+
if (b.stringEnd - start - quotes !== value.length) {
|
|
396
|
+
const error = stringError(input, start, b.stringEnd);
|
|
397
|
+
if (Option.isSome(error)) throw error.value;
|
|
398
|
+
}
|
|
399
|
+
return value;
|
|
400
|
+
}));
|
|
401
|
+
const datatype = Parser.alt(Parser.preceded(Parser.seq(Parser.not(lit("<<")), at("<")), iri), Parser.preceded(nameStart, prefixedName), failHere("Expected a datatype IRI"));
|
|
402
|
+
const languageTag = Parser.preceded(lit("@"), Parser.preceded(act((pos) => {
|
|
403
|
+
b.tagStart = pos;
|
|
404
|
+
}), Token.takeWhile([alphanumeric, "-"]))).pipe(Parser.map((text) => {
|
|
405
|
+
const tag = parseLanguageTag(text);
|
|
406
|
+
if (tag === void 0) throw new Stop("Invalid language tag", b.tagStart);
|
|
407
|
+
return tag;
|
|
408
|
+
}));
|
|
409
|
+
/** The literal read, with a language tag or datatype. */
|
|
410
|
+
const annotatedLiteral = (annotation) => {
|
|
411
|
+
const result = makeLiteral(b.literalValue, annotation);
|
|
412
|
+
if (Predicate.isString(result)) throw new Stop(result, b.literalStart);
|
|
413
|
+
return result;
|
|
414
|
+
};
|
|
415
|
+
const rdfLiteral = Parser.preceded(Parser.seq(act((pos) => {
|
|
416
|
+
b.literalStart = pos;
|
|
417
|
+
}), Parser.tap(string, (value) => {
|
|
418
|
+
b.literalValue = value;
|
|
419
|
+
}), skip), Parser.alt(languageTag.pipe(Parser.map(annotatedLiteral)), Parser.preceded(Parser.alt(lit("^^"), Parser.preceded(at("^"), failHere("Expected '^^'"))), Parser.preceded(skip, datatype)).pipe(Parser.map(annotatedLiteral)), Parser.make(() => literal(b.literalValue))));
|
|
420
|
+
const numericLiteral = Parser.alt(double.pipe(Parser.map((value) => new Literal(value, xsd.double))), decimal.pipe(Parser.map((value) => new Literal(value, xsd.decimal))), integer.pipe(Parser.map((value) => new Literal(value, xsd.integer))), failHere("Invalid number"));
|
|
421
|
+
const trueLiteral = new Literal("true", xsd.boolean);
|
|
422
|
+
const falseLiteral = new Literal("false", xsd.boolean);
|
|
423
|
+
const booleanLiteral = Parser.alt(Parser.terminated(lit("true"), notName).pipe(Parser.as(trueLiteral)), Parser.terminated(lit("false"), notName).pipe(Parser.as(falseLiteral)));
|
|
424
|
+
/** Numbers, booleans and prefixed names. */
|
|
425
|
+
const simpleObject = Parser.alt(Parser.preceded(Parser.peek(Token.oneOf("0123456789+-.")), numericLiteral), booleanLiteral, Parser.preceded(nameStart, prefixedName), failHere("Expected an object"));
|
|
426
|
+
const anon = Parser.seq(lit("["), Token.takeWhile(" \r\n"), lit("]")).pipe(Parser.map(() => b.fresh()));
|
|
427
|
+
/** `iri | BlankNode`, including `[]`. */
|
|
428
|
+
const iriOrBlankNode = (what) => Parser.alt(Parser.preceded(at("["), Parser.alt(anon, failHere(`Blank node property lists are not allowed in ${what}`))), Parser.preceded(at("<<"), failHere(`Unexpected triple in ${what}`)), Parser.preceded(at("("), failHere(`Collections are not allowed in ${what}`)), Parser.preceded(Parser.peek(Token.oneOf("<_:")), resource), Parser.preceded(Parser.seq(Parser.peek(Token.oneOf(pnCharsBase)), Parser.not(booleanLiteral)), resource), failHere(`Expected an IRI or blank node in ${what}`));
|
|
429
|
+
const verb = Parser.alt(Parser.preceded(at("<<"), failHere("Triples are not allowed as predicates")), Parser.preceded(at("<"), iri), Parser.terminated(lit("a"), notName).pipe(Parser.as(rdf.type)), Parser.preceded(nameStart, prefixedName), failHere("Expected a predicate"));
|
|
430
|
+
const tripleTerm = Parser.suspend(() => tripleTermDef);
|
|
431
|
+
const reifiedTriple = Parser.suspend(() => reifiedTripleDef);
|
|
432
|
+
const object = Parser.suspend(() => objectDef);
|
|
433
|
+
const predicateObjectList = Parser.suspend(() => predicateObjectListDef);
|
|
434
|
+
/** The object of a reified triple or triple term. */
|
|
435
|
+
const innerObject = (reified) => {
|
|
436
|
+
const what = reified ? "reified triples" : "triple terms";
|
|
437
|
+
return Parser.alt(Parser.preceded(at("<<("), tripleTerm), Parser.preceded(at("<<"), reified ? reifiedTriple : failHere("Reified triples are not allowed in triple terms")), Parser.preceded(Parser.peek(Token.oneOf("<_")), resource), Parser.preceded(at("["), Parser.alt(anon, failHere(`Blank node property lists are not allowed in ${what}`))), Parser.preceded(at("("), failHere(`Collections are not allowed in ${what}`)), Parser.preceded(Parser.peek(Token.oneOf("\"'")), rdfLiteral), simpleObject);
|
|
438
|
+
};
|
|
439
|
+
const tripleTermDef = Parser.seq(Parser.preceded(Parser.seq(lit("<<("), skip), iriOrBlankNode("the subject of a triple term")), Parser.preceded(skip, verb), Parser.preceded(skip, innerObject(false)), Parser.preceded(skip, Parser.alt(lit(")>>"), failHere("Expected ')>>'")))).pipe(Parser.map(([s, p, o]) => new Triple(s, p, o)));
|
|
440
|
+
const startsReifierId = Parser.peek(Parser.alt(Parser.preceded(Parser.not(lit("<<")), lit("<")), lit("_:"), anon, lit(":"), Token.oneOf(pnCharsBase)));
|
|
441
|
+
/** A reifier IRI or blank node, including `[]`. */
|
|
442
|
+
const reifierId = Parser.preceded(startsReifierId, Parser.alt(Parser.preceded(at("["), anon), resource));
|
|
443
|
+
const reifiedTripleDef = Parser.seq(Parser.preceded(Parser.seq(lit("<<"), skip), Parser.alt(Parser.preceded(Parser.seq(at("<<"), Parser.not(lit("<<("))), reifiedTriple), iriOrBlankNode("the subject of a reified triple"))), Parser.preceded(skip, verb), Parser.preceded(skip, innerObject(true)), Parser.preceded(skip, Parser.opt(Parser.preceded(Parser.seq(lit("~"), skip), Parser.terminated(Parser.opt(reifierId), skip)))), Parser.alt(lit(">>"), failHere("Expected '>>'"))).pipe(Parser.map(([s, p, o, r]) => {
|
|
444
|
+
const reifier = Option.getOrElse(Option.flatten(r), () => b.fresh());
|
|
445
|
+
b.emit(reifier, rdf.reifies, new Triple(s, p, o));
|
|
446
|
+
return reifier;
|
|
447
|
+
}));
|
|
448
|
+
const blankNodePropertyList = Parser.seq(Parser.tap(lit("[").pipe(Parser.map(() => b.fresh())), (node) => b.push(node)), Parser.preceded(skip, predicateObjectList), Parser.preceded(skip, Parser.alt(lit("]"), failHere("Expected ']'")))).pipe(Parser.tap(() => {
|
|
449
|
+
b.depth--;
|
|
450
|
+
}), Parser.map(([node]) => node));
|
|
451
|
+
const collection = Parser.preceded(Parser.seq(lit("("), skip), Parser.terminated(Parser.repeat(Parser.preceded(Parser.seq(Parser.not(lit(")")), Parser.not(Parser.eof)), Parser.terminated(object, skip))), Parser.alt(lit(")"), failHere("Expected ')'")))).pipe(Parser.map((items) => {
|
|
452
|
+
if (Arr.isReadonlyArrayEmpty(items)) return rdf.nil;
|
|
453
|
+
const head = b.fresh();
|
|
454
|
+
Arr.reduce(items, head, (cell, item, i) => {
|
|
455
|
+
b.emit(cell, rdf.first, item);
|
|
456
|
+
const next = i + 1 < items.length ? b.fresh() : rdf.nil;
|
|
457
|
+
b.emit(cell, rdf.rest, next);
|
|
458
|
+
return next;
|
|
459
|
+
});
|
|
460
|
+
return head;
|
|
461
|
+
}));
|
|
462
|
+
/**
|
|
463
|
+
* A parser as a rule of its own: the compiler inlines everything between
|
|
464
|
+
* rules, and leaves inlined into the recursive productions would make their
|
|
465
|
+
* stack frames (and so the nesting the parser supports) much larger.
|
|
466
|
+
*/
|
|
467
|
+
const rule = (p) => Parser.suspend(() => p);
|
|
468
|
+
const objectDef = Parser.alt(Parser.preceded(at("<<("), tripleTerm), Parser.preceded(at("<<"), reifiedTriple), Parser.preceded(at("<"), rule(iri)), Parser.preceded(at("_:"), rule(blankNode)), Parser.preceded(at("_"), rule(prefixedName)), Parser.preceded(at("["), Parser.alt(rule(anon), rule(blankNodePropertyList))), Parser.preceded(at("("), rule(collection)), Parser.preceded(Parser.peek(Token.oneOf("\"'")), rule(rdfLiteral)), rule(simpleObject));
|
|
469
|
+
const freshNode = Parser.make(() => b.fresh());
|
|
470
|
+
const emitObject = Parser.tap(object, (o) => {
|
|
471
|
+
const frame = b.frame();
|
|
472
|
+
b.emit(frame.subject, frame.predicate, o);
|
|
473
|
+
frame.object = o;
|
|
474
|
+
frame.reifier = noReifier;
|
|
475
|
+
frame.triple = noTriple;
|
|
476
|
+
});
|
|
477
|
+
/** The triple of the frame's current object, built once. */
|
|
478
|
+
const frameTriple = (frame) => {
|
|
479
|
+
if (Option.isSome(frame.triple)) return frame.triple.value;
|
|
480
|
+
const triple = new Triple(frame.subject, frame.predicate, frame.object);
|
|
481
|
+
frame.triple = Option.some(triple);
|
|
482
|
+
return triple;
|
|
483
|
+
};
|
|
484
|
+
const reifies = (frame, reifier) => {
|
|
485
|
+
b.emit(reifier, rdf.reifies, frameTriple(frame));
|
|
486
|
+
};
|
|
487
|
+
const annotation = Parser.repeat(Parser.preceded(skip, Parser.alt(Parser.tap(Parser.preceded(Parser.seq(lit("~"), skip), Parser.alt(reifierId, freshNode)), (reifier) => {
|
|
488
|
+
const frame = b.frame();
|
|
489
|
+
reifies(frame, reifier);
|
|
490
|
+
frame.reifier = Option.some(reifier);
|
|
491
|
+
}), Parser.seq(Parser.tap(lit("{|"), () => {
|
|
492
|
+
const frame = b.frame();
|
|
493
|
+
if (Option.isSome(frame.reifier)) {
|
|
494
|
+
b.push(frame.reifier.value);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const reifier = b.fresh();
|
|
498
|
+
frame.reifier = Option.some(reifier);
|
|
499
|
+
reifies(frame, reifier);
|
|
500
|
+
b.push(reifier);
|
|
501
|
+
}), Parser.preceded(skip, predicateObjectList), Parser.preceded(skip, Parser.alt(lit("|}"), failHere("Expected '|}'")))).pipe(Parser.tap(() => {
|
|
502
|
+
b.depth--;
|
|
503
|
+
b.frame().reifier = noReifier;
|
|
504
|
+
})))));
|
|
505
|
+
const objectList = Parser.seq(emitObject, rule(annotation), skip, Parser.repeat(Parser.preceded(Parser.seq(lit(","), skip), Parser.seq(emitObject, annotation, skip))));
|
|
506
|
+
const setPredicate = Parser.tap(rule(verb), (p) => {
|
|
507
|
+
b.frame().predicate = p;
|
|
508
|
+
});
|
|
509
|
+
const startsVerb = Parser.peek(Parser.alt(Parser.preceded(Parser.not(lit("<<")), lit("<")), lit(":"), Token.oneOf(pnCharsBase)));
|
|
510
|
+
const predicateObjectListDef = Parser.seq(setPredicate, skip, objectList, Parser.repeat(Parser.preceded(Parser.repeat(Parser.seq(lit(";"), skip), { min: 1 }), Parser.opt(Parser.preceded(startsVerb, Parser.seq(setPredicate, skip, objectList))))));
|
|
511
|
+
/** `subject` (pushed while `rest` describes it). */
|
|
512
|
+
const describing = (subject, rest) => Parser.terminated(Parser.preceded(Parser.tap(subject, (s) => b.push(s)), rest), act(() => {
|
|
513
|
+
b.depth--;
|
|
514
|
+
}));
|
|
515
|
+
const notEnd = Parser.not(Token.oneOf(".}"));
|
|
516
|
+
const properties = Parser.preceded(skip, predicateObjectList);
|
|
517
|
+
const optionalProperties = Parser.preceded(skip, Parser.opt(Parser.preceded(notEnd, predicateObjectList)));
|
|
518
|
+
/** The `triples` production. */
|
|
519
|
+
const triples = Parser.alt(Parser.preceded(at("["), Parser.alt(describing(anon, properties), describing(blankNodePropertyList, optionalProperties))), Parser.preceded(at("("), describing(collection, properties)), Parser.preceded(at("<<("), failHere("Triple terms are not allowed as subjects")), Parser.preceded(at("<<"), describing(reifiedTriple, optionalProperties)), describing(resource, properties));
|
|
520
|
+
const prefixDirective = (turtle) => Parser.seq(Parser.tap(Parser.preceded(skip, Parser.seq(Parser.location, prefixLabel, Parser.opt(lit(":")))), ([start, , colon]) => {
|
|
521
|
+
if (Option.isNone(colon)) throw new Stop("Expected a prefix name ending with \":\"", start);
|
|
522
|
+
}), Parser.preceded(skip, Parser.alt(Parser.preceded(at("<"), iri), failHere("Expected an IRI"))), turtle ? Parser.preceded(skip, expectDot("'.' after @prefix")) : Parser.succeed(void 0)).pipe(Parser.tap(([[, prefix], ref]) => {
|
|
523
|
+
b.setPrefix(prefix, ref.value);
|
|
524
|
+
}));
|
|
525
|
+
const baseDirective = (turtle) => Parser.seq(Parser.preceded(skip, Parser.alt(Parser.preceded(at("<"), iri), failHere("Expected an IRI"))), turtle ? Parser.preceded(skip, expectDot("'.' after @base")) : Parser.succeed(void 0)).pipe(Parser.tap(([ref]) => {
|
|
526
|
+
b.base = Option.some(ref.value);
|
|
527
|
+
}));
|
|
528
|
+
const versionDirective = (turtle) => Parser.seq(Parser.preceded(skip, Parser.alt(Parser.preceded(Parser.peek(Parser.alt(lit("\"\"\""), lit("'''"))), failHere("Long strings are not allowed as version specifiers")), Parser.preceded(Parser.peek(Token.oneOf("\"'")), string), failHere("Expected a version string"))), turtle ? Parser.preceded(skip, expectDot("'.' after @version")) : Parser.succeed(void 0));
|
|
529
|
+
const directive = Parser.alt(Parser.preceded(at("@"), Parser.alt(Parser.preceded(atKeyword("@prefix"), prefixDirective(true)), Parser.preceded(atKeyword("@base"), baseDirective(true)), Parser.preceded(atKeyword("@version"), versionDirective(true)), failHere("Unknown directive"))), Parser.preceded(keyword("prefix"), prefixDirective(false)), Parser.preceded(keyword("base"), baseDirective(false)), Parser.preceded(keyword("version"), versionDirective(false)));
|
|
530
|
+
const endOfStatement = Parser.preceded(skip, expectDot("'.' at the end of the statement"));
|
|
531
|
+
const turtleStatement = Parser.alt(directive, Parser.seq(triples, endOfStatement));
|
|
532
|
+
const pending = (p) => Parser.tap(p, (node) => {
|
|
533
|
+
b.pending = node;
|
|
534
|
+
});
|
|
535
|
+
/** A graph block opened with `{` after `pending`, or properties of `pending`. */
|
|
536
|
+
const graphOrProperties = Parser.preceded(skip, Parser.alt(Parser.tap(lit("{"), () => b.openGraph(b.pending)), Parser.seq(describing(Parser.make(() => b.pending), predicateObjectList), endOfStatement)));
|
|
537
|
+
const graphLabel = Parser.alt(Parser.preceded(at("["), Parser.alt(anon, failHere("Expected a graph name"))), resource);
|
|
538
|
+
/** A TriG block outside graphs. */
|
|
539
|
+
const block = Parser.alt(Parser.tap(lit("{"), () => b.openGraph(defaultGraph)), Parser.preceded(keyword("graph"), Parser.seq(pending(Parser.preceded(skip, graphLabel)), Parser.preceded(skip, Parser.alt(lit("{"), failHere("Expected '{' after graph name")))).pipe(Parser.tap(() => b.openGraph(b.pending)))), Parser.preceded(at("["), Parser.alt(Parser.preceded(pending(anon), graphOrProperties), Parser.seq(describing(blankNodePropertyList, Parser.preceded(skip, Parser.opt(Parser.preceded(Parser.not(lit(".")), predicateObjectList)))), endOfStatement))), Parser.preceded(at("("), Parser.seq(describing(collection, properties), endOfStatement)), Parser.preceded(at("<<("), failHere("Triple terms are not allowed as subjects")), Parser.preceded(at("<<"), Parser.seq(describing(reifiedTriple, Parser.preceded(skip, Parser.opt(Parser.preceded(Parser.not(lit(".")), predicateObjectList)))), endOfStatement)), Parser.preceded(pending(resource), graphOrProperties));
|
|
540
|
+
/** Whether a TriG graph block is open (consuming nothing). */
|
|
541
|
+
const inGraph = Parser.make((state) => b.inGraph ? void 0 : state.backtrack("Verify", ["a graph block"]));
|
|
542
|
+
const graphStatement = Parser.alt(Parser.tap(lit("}"), () => {
|
|
543
|
+
b.inGraph = false;
|
|
544
|
+
b.graph = b.options.graph;
|
|
545
|
+
}), Parser.seq(triples, skip, Parser.alt(lit("."), at("}"), failHere("Expected '.' or '}'"))));
|
|
546
|
+
const trigStatement = Parser.alt(Parser.preceded(inGraph, graphStatement), directive, block);
|
|
547
|
+
/** Records the state at the start of a statement. */
|
|
548
|
+
const beginStatement = Parser.make((state) => {
|
|
549
|
+
b.snapshot(state.pos);
|
|
550
|
+
});
|
|
551
|
+
/**
|
|
552
|
+
* Ends a statement, unless the input may continue so close to its end that
|
|
553
|
+
* the statement could still turn out differently.
|
|
554
|
+
*/
|
|
555
|
+
const endStatement = Parser.make((state) => {
|
|
556
|
+
if (!b.final) {
|
|
557
|
+
const input = state.input;
|
|
558
|
+
if (skipDots(input, state.pos) + MARGIN > input.length) return state.backtrack("Verify", ["more input"]);
|
|
559
|
+
}
|
|
560
|
+
b.open = false;
|
|
561
|
+
b.lastEnd = state.pos;
|
|
562
|
+
});
|
|
563
|
+
/** Starts a run: the compiled run, or the interpreted re-run after it fails. */
|
|
564
|
+
const startRun = Parser.make((state) => {
|
|
565
|
+
b.input = state.input;
|
|
566
|
+
b.restartRun();
|
|
567
|
+
});
|
|
568
|
+
const statements = (statement) => Compiler.jit(Parser.preceded(startRun, Parser.preceded(Parser.repeat(Parser.preceded(skip, Parser.preceded(Parser.not(Parser.eof), Parser.delimited(beginStatement, statement, endStatement)))), Parser.preceded(skip, Parser.location))));
|
|
569
|
+
const turtleStatements = statements(turtleStatement);
|
|
570
|
+
const trigStatements = statements(trigStatement);
|
|
571
|
+
/** One statement, for the partial-mode check (setting the input first). */
|
|
572
|
+
const single = (statement) => Parser.preceded(Parser.make((state) => {
|
|
573
|
+
b.input = state.input;
|
|
574
|
+
}), statement);
|
|
575
|
+
const turtleSingle = single(turtleStatement);
|
|
576
|
+
const trigSingle = single(trigStatement);
|
|
577
|
+
/** @internal */
|
|
578
|
+
var TurtleParser = class {
|
|
579
|
+
input = "";
|
|
580
|
+
pos = 0;
|
|
581
|
+
final = true;
|
|
582
|
+
/** Lines and columns consumed before the start of `input`. */
|
|
583
|
+
lineOffset = 0;
|
|
584
|
+
columnOffset = 0;
|
|
585
|
+
started = false;
|
|
586
|
+
builder;
|
|
587
|
+
/** How much text the failing statement at `pos` had when it was last checked (or -1). */
|
|
588
|
+
checked = -1;
|
|
589
|
+
options;
|
|
590
|
+
constructor(options) {
|
|
591
|
+
this.options = options;
|
|
592
|
+
this.builder = new Builder(options);
|
|
593
|
+
}
|
|
594
|
+
get prefixes() {
|
|
595
|
+
return this.builder.prefixes;
|
|
596
|
+
}
|
|
597
|
+
get base() {
|
|
598
|
+
return this.builder.base;
|
|
599
|
+
}
|
|
600
|
+
/** Parses a complete document. */
|
|
601
|
+
parseDocument(input) {
|
|
602
|
+
this.input = input;
|
|
603
|
+
this.pos = 0;
|
|
604
|
+
this.final = true;
|
|
605
|
+
this.skipBom();
|
|
606
|
+
this.run();
|
|
607
|
+
return this.finish();
|
|
608
|
+
}
|
|
609
|
+
/** Adds a chunk of input and returns the statements completed so far. */
|
|
610
|
+
feed(chunk) {
|
|
611
|
+
this.discardConsumed();
|
|
612
|
+
this.input += chunk;
|
|
613
|
+
this.final = false;
|
|
614
|
+
this.skipBom();
|
|
615
|
+
this.run();
|
|
616
|
+
return this.take();
|
|
617
|
+
}
|
|
618
|
+
/** Signals the end of input and returns the remaining statements. */
|
|
619
|
+
end() {
|
|
620
|
+
this.final = true;
|
|
621
|
+
this.run();
|
|
622
|
+
return this.finish();
|
|
623
|
+
}
|
|
624
|
+
finish() {
|
|
625
|
+
if (this.builder.inGraph) this.fail("Unterminated graph block: expected '}'");
|
|
626
|
+
return this.take();
|
|
627
|
+
}
|
|
628
|
+
take() {
|
|
629
|
+
const out = this.builder.out;
|
|
630
|
+
this.builder.out = [];
|
|
631
|
+
return out;
|
|
632
|
+
}
|
|
633
|
+
skipBom() {
|
|
634
|
+
if (this.started) return;
|
|
635
|
+
if (Str.isEmpty(this.input)) return;
|
|
636
|
+
this.started = true;
|
|
637
|
+
if (this.input.charCodeAt(0) === 65279) this.pos = 1;
|
|
638
|
+
}
|
|
639
|
+
discardConsumed() {
|
|
640
|
+
if (this.pos === 0) return;
|
|
641
|
+
const consumed = this.input.slice(0, this.pos);
|
|
642
|
+
const lastBreak = Math.max(consumed.lastIndexOf("\n"), consumed.lastIndexOf("\r"));
|
|
643
|
+
if (lastBreak === -1) this.columnOffset += consumed.length;
|
|
644
|
+
else {
|
|
645
|
+
this.lineOffset += countLines(consumed);
|
|
646
|
+
this.columnOffset = consumed.length - lastBreak - 1;
|
|
647
|
+
}
|
|
648
|
+
this.input = this.input.slice(this.pos);
|
|
649
|
+
this.pos = 0;
|
|
650
|
+
}
|
|
651
|
+
/** Parses the statements of the buffered input. */
|
|
652
|
+
run() {
|
|
653
|
+
const base = this.pos;
|
|
654
|
+
const input = base === 0 ? this.input : this.input.slice(base);
|
|
655
|
+
const builder = this.builder;
|
|
656
|
+
b = builder;
|
|
657
|
+
builder.final = this.final;
|
|
658
|
+
builder.beginRun();
|
|
659
|
+
const outcome = Result.try({
|
|
660
|
+
try: () => {
|
|
661
|
+
const result = Parser.parsePeek(this.options.trig ? trigStatements : turtleStatements, input);
|
|
662
|
+
if (Result.isFailure(result)) this.fail("Invalid syntax", base + result.failure.offset);
|
|
663
|
+
const [, end] = result.success;
|
|
664
|
+
if (this.final) {
|
|
665
|
+
if (end < input.length) this.fail("Invalid syntax", base + end);
|
|
666
|
+
this.pos = base + end;
|
|
667
|
+
} else {
|
|
668
|
+
builder.rollback();
|
|
669
|
+
this.pos = base + builder.lastEnd;
|
|
670
|
+
this.checked = -1;
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
catch: (e) => {
|
|
674
|
+
if (e instanceof Stop) return e;
|
|
675
|
+
throw e;
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
if (Result.isFailure(outcome)) {
|
|
679
|
+
const e = outcome.failure;
|
|
680
|
+
builder.rollback();
|
|
681
|
+
if (this.final) this.fail(e.message, base + e.pos);
|
|
682
|
+
const start = builder.snapPos;
|
|
683
|
+
const remaining = input.length - start;
|
|
684
|
+
if (start !== 0 || this.checked < 0 || remaining < 2 * this.checked) {
|
|
685
|
+
if (start !== 0 || this.checked < 0) this.checked = remaining;
|
|
686
|
+
this.pos = base + start;
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
this.checked = remaining;
|
|
690
|
+
this.check(input, base);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Before the input is complete, re-reads the statement that failed in
|
|
695
|
+
* partial mode: it fails again if the error is real, and runs out of input
|
|
696
|
+
* if the statement is only cut off.
|
|
697
|
+
*/
|
|
698
|
+
check(input, base) {
|
|
699
|
+
const builder = this.builder;
|
|
700
|
+
const start = builder.snapPos;
|
|
701
|
+
builder.open = true;
|
|
702
|
+
const outcome = Result.try({
|
|
703
|
+
try: () => {
|
|
704
|
+
const result = Parser.parsePartial(this.options.trig ? trigSingle : turtleSingle, input.slice(start));
|
|
705
|
+
if (Result.isFailure(result)) this.fail("Invalid syntax", base + start + result.failure.offset);
|
|
706
|
+
},
|
|
707
|
+
catch: (e) => {
|
|
708
|
+
if (e instanceof Stop) return e;
|
|
709
|
+
throw e;
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
if (Result.isFailure(outcome)) {
|
|
713
|
+
builder.rollback();
|
|
714
|
+
this.fail(outcome.failure.message, base + start + outcome.failure.pos);
|
|
715
|
+
}
|
|
716
|
+
builder.rollback();
|
|
717
|
+
builder.open = false;
|
|
718
|
+
this.pos = base + start;
|
|
719
|
+
}
|
|
720
|
+
fail(message, pos = this.pos) {
|
|
721
|
+
const before = this.input.slice(0, pos);
|
|
722
|
+
const lines = countLines(before);
|
|
723
|
+
const lastBreak = Math.max(before.lastIndexOf("\n"), before.lastIndexOf("\r"));
|
|
724
|
+
const column = lines === 0 ? this.columnOffset + pos + 1 : pos - lastBreak;
|
|
725
|
+
throw new SyntaxFailure(message, this.lineOffset + lines + 1, column);
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
/** A line break: `\r\n`, `\r` or `\n`. */
|
|
729
|
+
const LINE_BREAK = /\r\n?|\n/g;
|
|
730
|
+
const countLines = (text) => {
|
|
731
|
+
let n = 0;
|
|
732
|
+
LINE_BREAK.lastIndex = 0;
|
|
733
|
+
loop(() => {
|
|
734
|
+
if (!LINE_BREAK.test(text)) return false;
|
|
735
|
+
n++;
|
|
736
|
+
return true;
|
|
737
|
+
});
|
|
738
|
+
return n;
|
|
739
|
+
};
|
|
740
|
+
// src/turtle/internal/parse.ts
|
|
741
|
+
const makeParser = (syntax, options) => new TurtleParser({
|
|
742
|
+
trig: syntax.trig,
|
|
743
|
+
baseIri: Option.fromUndefinedOr(options?.baseIri),
|
|
744
|
+
blankNodePrefix: options?.blankNodePrefix ?? freshBlankNodePrefix(),
|
|
745
|
+
graph: (syntax.trig ? void 0 : options?.graph) ?? defaultGraph
|
|
746
|
+
});
|
|
747
|
+
/**
|
|
748
|
+
* Maps what a parse threw — a `SyntaxFailure`, or a defect as an `Error` or
|
|
749
|
+
* its string form — to an `RdfParseError`.
|
|
750
|
+
*/
|
|
751
|
+
const toParseError = (syntax, error) => error instanceof SyntaxFailure ? new RdfParseError({
|
|
752
|
+
format: syntax.name,
|
|
753
|
+
message: error.message,
|
|
754
|
+
line: error.line,
|
|
755
|
+
column: error.column
|
|
756
|
+
}) : new RdfParseError({
|
|
757
|
+
format: syntax.name,
|
|
758
|
+
message: Predicate.isString(error) ? error : error.message
|
|
759
|
+
});
|
|
760
|
+
/** @internal */
|
|
761
|
+
const parseQuads = (syntax, input, options) => Effect.try({
|
|
762
|
+
try: () => {
|
|
763
|
+
const parser = makeParser(syntax, options);
|
|
764
|
+
return {
|
|
765
|
+
quads: parser.parseDocument(input),
|
|
766
|
+
prefixes: make(parser.prefixes),
|
|
767
|
+
baseIri: Option.getOrUndefined(parser.base)
|
|
768
|
+
};
|
|
769
|
+
},
|
|
770
|
+
catch: (error) => toParseError(syntax, Predicate.isError(error) ? error : String(error))
|
|
771
|
+
});
|
|
772
|
+
/** @internal */
|
|
773
|
+
const parse = (syntax, input, options) => Effect.map(parseQuads(syntax, input, options), (result) => ({
|
|
774
|
+
dataset: fromIterable(result.quads),
|
|
775
|
+
prefixes: result.prefixes,
|
|
776
|
+
baseIri: result.baseIri
|
|
777
|
+
})).pipe(withParseSpan(Option.getOrUndefined(syntax.trace), input));
|
|
778
|
+
const END = Symbol("end");
|
|
779
|
+
/** @internal */
|
|
780
|
+
const parseStream = (syntax) => (input, options) => Stream.suspend(() => {
|
|
781
|
+
const parser = makeParser(syntax, options);
|
|
782
|
+
return Stream.concat(input, Stream.succeed(END)).pipe(Stream.mapAccumArrayEffect(() => void 0, (_, chunks) => Effect.try({
|
|
783
|
+
try: () => [void 0, Arr.flatMap(chunks, (chunk) => chunk === END ? parser.end() : parser.feed(chunk))],
|
|
784
|
+
catch: (error) => toParseError(syntax, Predicate.isError(error) ? error : String(error))
|
|
785
|
+
})));
|
|
786
|
+
}).pipe(withStreamSpan(Option.getOrUndefined(syntax.trace), "parseStream"));
|
|
787
|
+
// src/turtle/internal/writer.ts
|
|
788
|
+
/**
|
|
789
|
+
* Pretty-printing writer shared by the Turtle and TriG serializers.
|
|
790
|
+
*
|
|
791
|
+
* @internal
|
|
792
|
+
*/
|
|
793
|
+
/** @internal */
|
|
794
|
+
var SerializeFailure = class extends Error {};
|
|
795
|
+
const RDF_TYPE = rdf.type.value;
|
|
796
|
+
const RDF_FIRST = rdf.first.value;
|
|
797
|
+
const RDF_REST = rdf.rest.value;
|
|
798
|
+
const RDF_NIL = rdf.nil.value;
|
|
799
|
+
const RDF_REIFIES = rdf.reifies.value;
|
|
800
|
+
const XSD_INTEGER = xsd.integer.value;
|
|
801
|
+
const XSD_DECIMAL = xsd.decimal.value;
|
|
802
|
+
const XSD_DOUBLE = xsd.double.value;
|
|
803
|
+
const XSD_BOOLEAN = xsd.boolean.value;
|
|
804
|
+
const INTEGER = /^[+-]?[0-9]+$/;
|
|
805
|
+
const DECIMAL = /^[+-]?[0-9]*\.[0-9]+$/;
|
|
806
|
+
const DOUBLE = /^[+-]?(?:[0-9]+\.[0-9]*[eE][+-]?[0-9]+|\.[0-9]+[eE][+-]?[0-9]+|[0-9]+[eE][+-]?[0-9]+)$/;
|
|
807
|
+
/** Characters that may be backslash-escaped in a local name (minus URL delimiters). */
|
|
808
|
+
const LOCAL_ESCAPABLE = "_~.-!$&'()*+,;=@";
|
|
809
|
+
/** An ASCII local name that is already a `PN_LOCAL` (or empty): no character needs encoding. */
|
|
810
|
+
const PLAIN_LOCAL = /^(?:[A-Za-z0-9_:](?:[A-Za-z0-9_:.-]*[A-Za-z0-9_:-])?)?$/;
|
|
811
|
+
/**
|
|
812
|
+
* The characters a long (`"""`) string escapes: `\`, `"`, controls other than
|
|
813
|
+
* tab and line feed, and the noncharacters U+FFFE and U+FFFF. Written as what
|
|
814
|
+
* is kept, so that it names no control character.
|
|
815
|
+
*/
|
|
816
|
+
const LONG_ESCAPED = /[\\"]|[^\t\n -~\x80-\u{fffd}\u{10000}-\u{10ffff}]/gu;
|
|
817
|
+
/** The code point of a one-character string. */
|
|
818
|
+
const codePoint = (ch) => ch.codePointAt(0) ?? 0;
|
|
819
|
+
/** Whether `prefix` is a valid `PN_PREFIX` (or empty). */
|
|
820
|
+
const isPrefixName = (prefix) => {
|
|
821
|
+
if (prefix === "") return true;
|
|
822
|
+
const chars = Array.from(prefix, codePoint);
|
|
823
|
+
return Arr.isReadonlyArrayNonEmpty(chars) && isPnCharsBase(Arr.headNonEmpty(chars)) && Arr.lastNonEmpty(chars) !== 46 && chars.every((c) => isPnChars(c) || c === 46);
|
|
824
|
+
};
|
|
825
|
+
/** Encodes a local name character by character, escaping what `PN_LOCAL` needs escaped. */
|
|
826
|
+
const encodeLocalChars = (local) => {
|
|
827
|
+
const chars = Array.from(local);
|
|
828
|
+
const last = chars.length - 1;
|
|
829
|
+
let out = "";
|
|
830
|
+
let i = 0;
|
|
831
|
+
let ok = true;
|
|
832
|
+
loop(() => {
|
|
833
|
+
if (i > last) return false;
|
|
834
|
+
const ch = chars[i] ?? "";
|
|
835
|
+
const c = codePoint(ch);
|
|
836
|
+
if (i === 0 ? isPnCharsU(c) || c === 58 || isDigit(c) : isPnChars(c) || c === 58 || c === 46 && i !== last) {
|
|
837
|
+
out += ch;
|
|
838
|
+
i += 1;
|
|
839
|
+
return true;
|
|
840
|
+
}
|
|
841
|
+
const h1 = chars[i + 1] ?? "";
|
|
842
|
+
const h2 = chars[i + 2] ?? "";
|
|
843
|
+
if (c === 37 && i + 2 < chars.length && isHex(h1.charCodeAt(0)) && isHex(h2.charCodeAt(0))) {
|
|
844
|
+
out += ch + h1 + h2;
|
|
845
|
+
i += 3;
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
if (LOCAL_ESCAPABLE.includes(ch)) {
|
|
849
|
+
out += `\\${ch}`;
|
|
850
|
+
i += 1;
|
|
851
|
+
return true;
|
|
852
|
+
}
|
|
853
|
+
ok = false;
|
|
854
|
+
return false;
|
|
855
|
+
});
|
|
856
|
+
return ok ? Option.some(out) : Option.none();
|
|
857
|
+
};
|
|
858
|
+
/** Encodes a local name as `PN_LOCAL`, or returns `None` if it cannot be. */
|
|
859
|
+
const encodeLocalName = (local) => PLAIN_LOCAL.test(local) ? Option.some(local) : encodeLocalChars(local);
|
|
860
|
+
const hex4 = (c) => `\\u${c.toString(16).toUpperCase().padStart(4, "0")}`;
|
|
861
|
+
const escapeLong = (ch) => ch === "\\" ? "\\\\" : ch === "\"" ? "\\\"" : ch === "\r" ? "\\r" : hex4(ch.charCodeAt(0));
|
|
862
|
+
/** Formats a string as a Turtle string literal, using `"""` for multi-line text. */
|
|
863
|
+
const quoteString = (value) => value.includes("\n") ? `"""${value.replace(LONG_ESCAPED, escapeLong)}"""` : `"${escapeString(value)}"`;
|
|
864
|
+
/** Calls `f` for every blank node in `t`, looking inside triple terms. */
|
|
865
|
+
const visitBlankNodes = (t, f) => {
|
|
866
|
+
if (isBlankNode(t)) f(t);
|
|
867
|
+
else if (isTriple(t)) {
|
|
868
|
+
visitBlankNodes(t.subject, f);
|
|
869
|
+
visitBlankNodes(t.object, f);
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
/** Throws when a triple term's subject is itself a triple term, at any depth of objects. */
|
|
873
|
+
const checkTriple = (t) => {
|
|
874
|
+
if (isTriple(t.subject)) throw new SerializeFailure(`Triple terms cannot be the subject of a triple term in Turtle 1.2: ${t.key}`);
|
|
875
|
+
if (isTriple(t.object)) checkTriple(t.object);
|
|
876
|
+
};
|
|
877
|
+
/** @internal */
|
|
878
|
+
const checkQuad = (q, trig) => {
|
|
879
|
+
if (isTriple(q.subject)) throw new SerializeFailure(`Triple terms cannot be subjects in Turtle 1.2: ${q.key}`);
|
|
880
|
+
if (!isGround(q)) throw new SerializeFailure(`Cannot serialise non-ground quad ${q.key}`);
|
|
881
|
+
if (isTriple(q.object)) checkTriple(q.object);
|
|
882
|
+
if (!trig && !isDefaultGraph(q.graph)) throw new SerializeFailure(`Turtle cannot represent quads in named graphs: ${q.key}`);
|
|
883
|
+
};
|
|
884
|
+
const isIdAnnotation = Predicate.isTagged("Id");
|
|
885
|
+
/** Appends `value` to the list at `key`, creating the list on first use. */
|
|
886
|
+
const pushAt = (map, key, value) => {
|
|
887
|
+
const list = MutableHashMap.get(map, key);
|
|
888
|
+
if (Option.isSome(list)) list.value.push(value);
|
|
889
|
+
else MutableHashMap.set(map, key, [value]);
|
|
890
|
+
};
|
|
891
|
+
/**
|
|
892
|
+
* Groups `values` by key, in order of first appearance, calling `onFirst`
|
|
893
|
+
* with the first value of each group. A run of values with the same key
|
|
894
|
+
* (statements arrive grouped) is appended without a lookup.
|
|
895
|
+
*/
|
|
896
|
+
const groupBy = (values, keyOf, onFirst = () => void 0) => {
|
|
897
|
+
const groups = MutableHashMap.empty();
|
|
898
|
+
let lastKey = "";
|
|
899
|
+
let last = [];
|
|
900
|
+
values.forEach((value) => {
|
|
901
|
+
const key = keyOf(value);
|
|
902
|
+
if (Arr.isReadonlyArrayNonEmpty(last) && key === lastKey) {
|
|
903
|
+
last.push(value);
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
const found = MutableHashMap.get(groups, key);
|
|
907
|
+
if (Option.isSome(found)) {
|
|
908
|
+
found.value.push(value);
|
|
909
|
+
last = found.value;
|
|
910
|
+
} else {
|
|
911
|
+
last = [value];
|
|
912
|
+
MutableHashMap.set(groups, key, last);
|
|
913
|
+
onFirst(value, key);
|
|
914
|
+
}
|
|
915
|
+
lastKey = key;
|
|
916
|
+
});
|
|
917
|
+
return groups;
|
|
918
|
+
};
|
|
919
|
+
/** The list at `key`, or an empty one. */
|
|
920
|
+
const listAt = (map, key) => Option.getOrElse(MutableHashMap.get(map, key), () => []);
|
|
921
|
+
const byNamespaceLength = Order.flip(Order.mapInput(Order.Number, (c) => c.ns.length));
|
|
922
|
+
/** `rdf:type` first (written `a`), then by IRI. */
|
|
923
|
+
const byVerb = (a, b) => a === RDF_TYPE ? -1 : b === RDF_TYPE ? 1 : a < b ? -1 : a > b ? 1 : 0;
|
|
924
|
+
/** @internal */
|
|
925
|
+
var Writer = class {
|
|
926
|
+
prefixes;
|
|
927
|
+
/** Whether each of `prefixes` has been written. */
|
|
928
|
+
usedPrefixes = [];
|
|
929
|
+
/** The prefixes, longest namespace first (in declaration order for equal lengths). */
|
|
930
|
+
byLength;
|
|
931
|
+
blanks = MutableHashMap.empty();
|
|
932
|
+
/** The keys of the quads written, built when the first reifier is planned. */
|
|
933
|
+
assertedKeys = Option.none();
|
|
934
|
+
plan;
|
|
935
|
+
labels = MutableHashMap.empty();
|
|
936
|
+
rendered = MutableHashSet.empty();
|
|
937
|
+
options;
|
|
938
|
+
quads;
|
|
939
|
+
relabel;
|
|
940
|
+
constructor(options, quads, relabel = true) {
|
|
941
|
+
this.options = options;
|
|
942
|
+
this.quads = quads;
|
|
943
|
+
this.relabel = relabel;
|
|
944
|
+
const declared = MutableHashMap.empty();
|
|
945
|
+
if (options.autoPrefixes) Arr.forEach(detectPrefixes(quads, options.baseIri), ([p, ns]) => {
|
|
946
|
+
MutableHashMap.set(declared, p, ns);
|
|
947
|
+
});
|
|
948
|
+
if (Option.isSome(options.prefixes)) Iterable.forEach(options.prefixes.value.prefixes, ([p, ns]) => {
|
|
949
|
+
Arr.forEach(Arr.filter(Arr.fromIterable(declared), ([q, other]) => other === ns && q !== p), ([q]) => {
|
|
950
|
+
MutableHashMap.remove(declared, q);
|
|
951
|
+
});
|
|
952
|
+
MutableHashMap.set(declared, p, ns);
|
|
953
|
+
});
|
|
954
|
+
this.prefixes = Arr.filter(Arr.fromIterable(declared), ([p, ns]) => isPrefixName(p) && isWritableIri(ns));
|
|
955
|
+
this.byLength = Arr.sort(this.prefixes.map(([prefix, ns], index) => ({
|
|
956
|
+
prefix,
|
|
957
|
+
ns,
|
|
958
|
+
index
|
|
959
|
+
})), byNamespaceLength);
|
|
960
|
+
if (Option.isSome(options.baseIri) && !isWritableIri(options.baseIri.value)) throw new SerializeFailure(`Invalid base IRI <${options.baseIri.value}>`);
|
|
961
|
+
}
|
|
962
|
+
write() {
|
|
963
|
+
this.quads.forEach((q) => {
|
|
964
|
+
checkQuad(q, this.options.trig);
|
|
965
|
+
this.index(q);
|
|
966
|
+
});
|
|
967
|
+
const names = MutableHashMap.empty();
|
|
968
|
+
const byGraph = groupBy(this.quads, (q) => q.graph.key, (q, key) => MutableHashMap.set(names, key, q.graph));
|
|
969
|
+
const graphs = Arr.sort(Arr.fromIterable(names), Order.mapInput(compareTerms, ([, graph]) => graph)).map(([key, graph]) => ({
|
|
970
|
+
graph,
|
|
971
|
+
quads: listAt(byGraph, key)
|
|
972
|
+
}));
|
|
973
|
+
const body = Arr.reduce(graphs, "", (out, { graph, quads }) => isDefaultGraph(graph) ? out + this.writeGraph(graph, quads, 0) : `${out}${out === "" ? "" : "\n"}${this.term(graph)} {\n${this.writeGraph(graph, quads, 1)}}\n`);
|
|
974
|
+
return this.header() + body;
|
|
975
|
+
}
|
|
976
|
+
asserted() {
|
|
977
|
+
if (Option.isSome(this.assertedKeys)) return this.assertedKeys.value;
|
|
978
|
+
const keys = MutableHashSet.empty();
|
|
979
|
+
this.quads.forEach((q) => MutableHashSet.add(keys, q.key));
|
|
980
|
+
this.assertedKeys = Option.some(keys);
|
|
981
|
+
return keys;
|
|
982
|
+
}
|
|
983
|
+
header() {
|
|
984
|
+
const sparql = this.options.sparqlDirectives;
|
|
985
|
+
const out = Option.match(this.options.baseIri, {
|
|
986
|
+
onNone: () => "",
|
|
987
|
+
onSome: (iri) => sparql ? `BASE <${escapeIri(iri)}>\n` : `@base <${escapeIri(iri)}> .\n`
|
|
988
|
+
}) + Arr.sort(this.prefixes.filter((_, i) => this.usedPrefixes[i] === true), byPrefixName).map(([p, ns]) => sparql ? `PREFIX ${p}: <${escapeIri(ns)}>\n` : `@prefix ${p}: <${escapeIri(ns)}> .\n`).join("");
|
|
989
|
+
return out === "" ? "" : `${out}\n`;
|
|
990
|
+
}
|
|
991
|
+
info(b) {
|
|
992
|
+
const found = MutableHashMap.get(this.blanks, b.value);
|
|
993
|
+
if (Option.isSome(found)) return found.value;
|
|
994
|
+
const info = {
|
|
995
|
+
objectRefs: [],
|
|
996
|
+
inTripleTerm: false,
|
|
997
|
+
asGraph: false,
|
|
998
|
+
subjectGraph: Option.none(),
|
|
999
|
+
manyGraphs: false
|
|
1000
|
+
};
|
|
1001
|
+
MutableHashMap.set(this.blanks, b.value, info);
|
|
1002
|
+
return info;
|
|
1003
|
+
}
|
|
1004
|
+
index(q) {
|
|
1005
|
+
if (isBlankNode(q.subject)) {
|
|
1006
|
+
const info = this.info(q.subject);
|
|
1007
|
+
if (Option.isNone(info.subjectGraph)) info.subjectGraph = Option.some(q.graph.key);
|
|
1008
|
+
else if (info.subjectGraph.value !== q.graph.key) info.manyGraphs = true;
|
|
1009
|
+
}
|
|
1010
|
+
if (isBlankNode(q.object)) this.info(q.object).objectRefs.push(q);
|
|
1011
|
+
if (isTriple(q.object)) visitBlankNodes(q.object, (b) => {
|
|
1012
|
+
this.info(b).inTripleTerm = true;
|
|
1013
|
+
});
|
|
1014
|
+
if (isBlankNode(q.graph)) this.info(q.graph).asGraph = true;
|
|
1015
|
+
}
|
|
1016
|
+
/** Whether a blank node is local to `graph` and appears in no triple term or graph name. */
|
|
1017
|
+
isLocal(b, graph) {
|
|
1018
|
+
const info = this.info(b);
|
|
1019
|
+
return !info.inTripleTerm && !info.asGraph && !info.manyGraphs && (Option.isNone(info.subjectGraph) || info.subjectGraph.value === graph.key);
|
|
1020
|
+
}
|
|
1021
|
+
planGraph(graph, quads, demoted) {
|
|
1022
|
+
const subjects = MutableHashMap.empty();
|
|
1023
|
+
const bySubject = groupBy(quads, (q) => q.subject.key, (q, key) => MutableHashMap.set(subjects, key, q.subject));
|
|
1024
|
+
const consumed = /* @__PURE__ */ new WeakSet();
|
|
1025
|
+
const inline = MutableHashSet.empty();
|
|
1026
|
+
quads.forEach((q) => {
|
|
1027
|
+
const o = q.object;
|
|
1028
|
+
if (!isBlankNode(o) || MutableHashSet.has(demoted, o.value) || !this.isLocal(o, graph)) return;
|
|
1029
|
+
const refs = this.info(o).objectRefs;
|
|
1030
|
+
if (refs.length === 1 && refs[0]?.graph.key === graph.key) MutableHashSet.add(inline, o.value);
|
|
1031
|
+
});
|
|
1032
|
+
const lists = MutableHashMap.empty();
|
|
1033
|
+
const listCells = MutableHashSet.empty();
|
|
1034
|
+
const listShape = (label) => {
|
|
1035
|
+
if (!MutableHashSet.has(inline, label)) return Option.none();
|
|
1036
|
+
const own = listAt(bySubject, `_:${label}`);
|
|
1037
|
+
if (own.length !== 2) return Option.none();
|
|
1038
|
+
const first = Arr.findFirst(own, (q) => q.predicate.value === RDF_FIRST);
|
|
1039
|
+
const rest = Arr.findFirst(own, (q) => q.predicate.value === RDF_REST);
|
|
1040
|
+
return Option.isSome(first) && Option.isSome(rest) ? Option.some([first.value.object, rest.value.object]) : Option.none();
|
|
1041
|
+
};
|
|
1042
|
+
Iterable.forEach(inline, (label) => {
|
|
1043
|
+
if (Option.isNone(listShape(label))) return;
|
|
1044
|
+
const ref = Arr.head(this.info(blankNode$1(label)).objectRefs);
|
|
1045
|
+
if (Option.isNone(ref) || ref.value.predicate.value === RDF_REST && isBlankNode(ref.value.subject) && Option.isSome(listShape(ref.value.subject.value))) return;
|
|
1046
|
+
const items = [];
|
|
1047
|
+
const cells = [];
|
|
1048
|
+
let current = label;
|
|
1049
|
+
let ok = false;
|
|
1050
|
+
loop(() => {
|
|
1051
|
+
const shape = listShape(current);
|
|
1052
|
+
if (Option.isNone(shape) || cells.includes(current)) return false;
|
|
1053
|
+
const [item, next] = shape.value;
|
|
1054
|
+
cells.push(current);
|
|
1055
|
+
items.push(item);
|
|
1056
|
+
if (isNamedNode(next) && next.value === RDF_NIL) {
|
|
1057
|
+
ok = true;
|
|
1058
|
+
return false;
|
|
1059
|
+
}
|
|
1060
|
+
if (!isBlankNode(next)) return false;
|
|
1061
|
+
current = next.value;
|
|
1062
|
+
return true;
|
|
1063
|
+
});
|
|
1064
|
+
if (!ok) return;
|
|
1065
|
+
MutableHashMap.set(lists, label, items);
|
|
1066
|
+
Arr.forEach(cells, (cell) => {
|
|
1067
|
+
MutableHashSet.add(listCells, cell);
|
|
1068
|
+
Arr.forEach(listAt(bySubject, `_:${cell}`), (q) => {
|
|
1069
|
+
consumed.add(q);
|
|
1070
|
+
});
|
|
1071
|
+
});
|
|
1072
|
+
});
|
|
1073
|
+
const annotations = MutableHashMap.empty();
|
|
1074
|
+
const blockReifiers = MutableHashSet.empty();
|
|
1075
|
+
const reifiedSubjects = MutableHashMap.empty();
|
|
1076
|
+
const idReifiers = MutableHashSet.empty();
|
|
1077
|
+
/** A blank reifier of nothing else, described only here: written as a block or a subject. */
|
|
1078
|
+
const isStandalone = (r) => !MutableHashSet.has(demoted, r.value) && this.isLocal(r, graph) && Arr.isReadonlyArrayEmpty(this.info(r).objectRefs) && listAt(bySubject, r.key).filter((x) => x.predicate.value === RDF_REIFIES && !consumed.has(x)).length === 1;
|
|
1079
|
+
quads.forEach((q) => {
|
|
1080
|
+
if (q.predicate.value !== RDF_REIFIES || !isTriple(q.object)) return;
|
|
1081
|
+
const t = q.object;
|
|
1082
|
+
if (isTriple(t.subject)) return;
|
|
1083
|
+
const r = q.subject;
|
|
1084
|
+
if (isTriple(r)) return;
|
|
1085
|
+
const assertedKey = new Quad(t.subject, t.predicate, t.object, graph).key;
|
|
1086
|
+
const isAsserted = MutableHashSet.has(this.asserted(), assertedKey);
|
|
1087
|
+
if (isBlankNode(r) && isStandalone(r)) {
|
|
1088
|
+
consumed.add(q);
|
|
1089
|
+
if (isAsserted) {
|
|
1090
|
+
MutableHashSet.add(blockReifiers, r.value);
|
|
1091
|
+
pushAt(annotations, assertedKey, {
|
|
1092
|
+
_tag: "Block",
|
|
1093
|
+
reifier: r
|
|
1094
|
+
});
|
|
1095
|
+
} else MutableHashMap.set(reifiedSubjects, r.value, t);
|
|
1096
|
+
} else if (isAsserted && (isNamedNode(r) || !MutableHashSet.has(inline, r.value) && !MutableHashSet.has(listCells, r.value))) {
|
|
1097
|
+
consumed.add(q);
|
|
1098
|
+
if (isBlankNode(r)) MutableHashSet.add(idReifiers, r.value);
|
|
1099
|
+
pushAt(annotations, assertedKey, {
|
|
1100
|
+
_tag: "Id",
|
|
1101
|
+
reifier: r
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
return {
|
|
1106
|
+
graph,
|
|
1107
|
+
bySubject,
|
|
1108
|
+
subjects,
|
|
1109
|
+
inline,
|
|
1110
|
+
lists,
|
|
1111
|
+
listCells,
|
|
1112
|
+
annotations,
|
|
1113
|
+
blockReifiers,
|
|
1114
|
+
idReifiers,
|
|
1115
|
+
reifiedSubjects,
|
|
1116
|
+
consumed
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
writeGraph(graph, quads, level) {
|
|
1120
|
+
const demoted = MutableHashSet.empty();
|
|
1121
|
+
let out = "";
|
|
1122
|
+
loop(() => {
|
|
1123
|
+
this.plan = this.planGraph(graph, quads, demoted);
|
|
1124
|
+
this.rendered = MutableHashSet.empty();
|
|
1125
|
+
out = this.renderGraph(level);
|
|
1126
|
+
const before = MutableHashSet.size(demoted);
|
|
1127
|
+
Iterable.forEach(this.plan.inline, (label) => {
|
|
1128
|
+
if (!MutableHashSet.has(this.rendered, label) && !MutableHashSet.has(this.plan.listCells, label)) MutableHashSet.add(demoted, label);
|
|
1129
|
+
});
|
|
1130
|
+
Iterable.forEach(MutableHashMap.keys(this.plan.lists), (label) => {
|
|
1131
|
+
if (!MutableHashSet.has(this.rendered, label)) MutableHashSet.add(demoted, label);
|
|
1132
|
+
});
|
|
1133
|
+
return MutableHashSet.size(demoted) !== before;
|
|
1134
|
+
});
|
|
1135
|
+
return out;
|
|
1136
|
+
}
|
|
1137
|
+
renderGraph(level) {
|
|
1138
|
+
const plan = this.plan;
|
|
1139
|
+
const unsorted = Arr.filter(Arr.fromIterable(MutableHashMap.values(plan.subjects)), (s) => !(isBlankNode(s) && (MutableHashSet.has(plan.inline, s.value) || MutableHashSet.has(plan.listCells, s.value) || MutableHashSet.has(plan.blockReifiers, s.value))));
|
|
1140
|
+
const roots = Arr.sort(unsorted, compareTerms);
|
|
1141
|
+
return Arr.flatMap(roots, (s) => {
|
|
1142
|
+
const quads = listAt(plan.bySubject, s.key).filter((q) => !plan.consumed.has(q));
|
|
1143
|
+
const reified = isBlankNode(s) ? MutableHashMap.get(plan.reifiedSubjects, s.value) : Option.none();
|
|
1144
|
+
const head = Option.isSome(reified) ? this.reifiedTriple(reified.value) : this.term(s);
|
|
1145
|
+
if (Arr.isReadonlyArrayEmpty(quads)) return Option.isSome(reified) ? [`${this.pad(level)}${head} .\n`] : [];
|
|
1146
|
+
if (isBlankNode(s) && Option.isNone(reified) && !MutableHashSet.has(plan.idReifiers, s.value) && Arr.isReadonlyArrayEmpty(this.info(s).objectRefs) && this.isLocal(s, plan.graph)) return [`${this.pad(level)}${this.bracketed("[", "]", quads, level)} .\n`];
|
|
1147
|
+
return [`${this.pad(level)}${head} ${this.predicateObjectList(quads, level + 1)} .\n`];
|
|
1148
|
+
}).join(level === 0 ? "\n" : "");
|
|
1149
|
+
}
|
|
1150
|
+
pad(level) {
|
|
1151
|
+
return this.options.indent.repeat(level);
|
|
1152
|
+
}
|
|
1153
|
+
/** Renders `p o, o ; p o` with continuation lines at `level`. */
|
|
1154
|
+
predicateObjectList(quads, level) {
|
|
1155
|
+
const byPredicate = groupBy(quads, (q) => q.predicate.value);
|
|
1156
|
+
return Arr.sort(byPredicate, Order.mapInput(byVerb, ([p]) => p)).map(([p, list]) => {
|
|
1157
|
+
const objects = Arr.sort(list, Order.mapInput(compareTerms, (q) => q.object)).map((q) => this.objectWithAnnotations(q, level));
|
|
1158
|
+
return `${p === RDF_TYPE ? "a" : this.iri(p)} ${objects.join(", ")}`;
|
|
1159
|
+
}).join(` ;\n${this.pad(level)}`);
|
|
1160
|
+
}
|
|
1161
|
+
objectWithAnnotations(q, level) {
|
|
1162
|
+
let out = this.object(q.object, level);
|
|
1163
|
+
const annotations = MutableHashMap.get(this.plan.annotations, q.key);
|
|
1164
|
+
if (Option.isNone(annotations)) return out;
|
|
1165
|
+
let bare = "";
|
|
1166
|
+
let ids = "";
|
|
1167
|
+
Arr.forEach(Arr.sort(annotations.value, Order.mapInput(compareTerms, (x) => x.reifier)), (annotation) => {
|
|
1168
|
+
if (isIdAnnotation(annotation)) {
|
|
1169
|
+
ids += ` ~ ${this.term(annotation.reifier)}`;
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
const own = listAt(this.plan.bySubject, annotation.reifier.key).filter((x) => !this.plan.consumed.has(x));
|
|
1173
|
+
if (Arr.isReadonlyArrayEmpty(own)) bare += " ~";
|
|
1174
|
+
else out += ` ${this.bracketed("{|", "|}", own, level)}`;
|
|
1175
|
+
});
|
|
1176
|
+
return out + bare + ids;
|
|
1177
|
+
}
|
|
1178
|
+
/** Renders a bracketed property list (`[ ... ]` or `{| ... |}`). */
|
|
1179
|
+
bracketed(open, close, quads, level) {
|
|
1180
|
+
const single = this.predicateObjectList(quads, level + 1);
|
|
1181
|
+
if (!single.includes("\n") && single.length <= 60) return `${open} ${single} ${close}`;
|
|
1182
|
+
return `${open}\n${this.pad(level + 1)}${single}\n${this.pad(level)}${close}`;
|
|
1183
|
+
}
|
|
1184
|
+
object(o, level) {
|
|
1185
|
+
if (isBlankNode(o)) {
|
|
1186
|
+
const items = MutableHashMap.get(this.plan.lists, o.value);
|
|
1187
|
+
if (Option.isSome(items) && !MutableHashSet.has(this.rendered, o.value)) {
|
|
1188
|
+
MutableHashSet.add(this.rendered, o.value);
|
|
1189
|
+
const rendered = items.value.map((item) => this.object(item, level));
|
|
1190
|
+
const oneLine = `( ${rendered.join(" ")} )`;
|
|
1191
|
+
return oneLine.length <= 80 && !oneLine.includes("\n") ? oneLine : `(\n${rendered.map((r) => this.pad(level + 1) + r).join("\n")}\n${this.pad(level)})`;
|
|
1192
|
+
}
|
|
1193
|
+
if (MutableHashSet.has(this.plan.inline, o.value) && !MutableHashSet.has(this.rendered, o.value)) {
|
|
1194
|
+
MutableHashSet.add(this.rendered, o.value);
|
|
1195
|
+
const own = listAt(this.plan.bySubject, o.key).filter((x) => !this.plan.consumed.has(x));
|
|
1196
|
+
if (Arr.isReadonlyArrayEmpty(own)) return "[]";
|
|
1197
|
+
const only = own.length === 1 ? Arr.head(own) : Option.none();
|
|
1198
|
+
if (Option.isSome(only) && only.value.predicate.value === RDF_REIFIES && isTriple(only.value.object) && !isTriple(only.value.object.subject)) return this.reifiedTriple(only.value.object);
|
|
1199
|
+
return this.bracketed("[", "]", own, level);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
if (isNamedNode(o) && o.value === RDF_NIL) return "()";
|
|
1203
|
+
return this.term(o);
|
|
1204
|
+
}
|
|
1205
|
+
reifiedTriple(t) {
|
|
1206
|
+
return `<< ${this.term(t.subject)} ${this.predicate(t.predicate)} ${this.term(t.object)} >>`;
|
|
1207
|
+
}
|
|
1208
|
+
predicate(p) {
|
|
1209
|
+
return p.value === RDF_TYPE ? "a" : this.iri(p.value);
|
|
1210
|
+
}
|
|
1211
|
+
/** Renders a term without any abbreviation that depends on context. */
|
|
1212
|
+
term(t) {
|
|
1213
|
+
if (isNamedNode(t)) return this.iri(t.value);
|
|
1214
|
+
if (isBlankNode(t)) return `_:${this.label(t.value)}`;
|
|
1215
|
+
if (isLiteral(t)) return this.literal(t);
|
|
1216
|
+
if (isTriple(t)) return `<<( ${this.term(t.subject)} ${this.predicate(t.predicate)} ${this.term(t.object)} )>>`;
|
|
1217
|
+
throw new SerializeFailure(`Cannot serialise ${t._tag}`);
|
|
1218
|
+
}
|
|
1219
|
+
/** Output labels are assigned in order of first appearance. */
|
|
1220
|
+
label(value) {
|
|
1221
|
+
if (!this.relabel) return blankNodeLabel$1(value);
|
|
1222
|
+
const found = MutableHashMap.get(this.labels, value);
|
|
1223
|
+
if (Option.isSome(found)) return found.value;
|
|
1224
|
+
const label = `b${MutableHashMap.size(this.labels)}`;
|
|
1225
|
+
MutableHashMap.set(this.labels, value, label);
|
|
1226
|
+
return label;
|
|
1227
|
+
}
|
|
1228
|
+
literal(l) {
|
|
1229
|
+
const dt = l.datatype.value;
|
|
1230
|
+
if (l.language === "") {
|
|
1231
|
+
if (dt === XSD_INTEGER && INTEGER.test(l.value) || dt === XSD_DECIMAL && DECIMAL.test(l.value) || dt === XSD_DOUBLE && DOUBLE.test(l.value) || dt === XSD_BOOLEAN && (l.value === "true" || l.value === "false")) return l.value;
|
|
1232
|
+
}
|
|
1233
|
+
const lexical = quoteString(l.value);
|
|
1234
|
+
if (l.language !== "") {
|
|
1235
|
+
const language = l.language.toLowerCase();
|
|
1236
|
+
return l.direction === void 0 ? `${lexical}@${language}` : `${lexical}@${language}--${l.direction}`;
|
|
1237
|
+
}
|
|
1238
|
+
if (dt === "http://www.w3.org/2001/XMLSchema#string") return lexical;
|
|
1239
|
+
return `${lexical}^^${this.iri(dt)}`;
|
|
1240
|
+
}
|
|
1241
|
+
iri(iri) {
|
|
1242
|
+
if (!isWritableIri(iri)) throw new SerializeFailure(`Invalid or relative IRI <${iri}>`);
|
|
1243
|
+
const best = this.byLength.find((c) => iri.startsWith(c.ns) && Option.isSome(encodeLocalName(iri.slice(c.ns.length))));
|
|
1244
|
+
if (best !== void 0) {
|
|
1245
|
+
this.usedPrefixes[best.index] = true;
|
|
1246
|
+
return `${best.prefix}:${Option.getOrElse(encodeLocalName(iri.slice(best.ns.length)), () => "")}`;
|
|
1247
|
+
}
|
|
1248
|
+
if (Option.isSome(this.options.baseIri)) {
|
|
1249
|
+
const relative = relativize(iri, this.options.baseIri.value);
|
|
1250
|
+
if (Option.isSome(relative)) return `<${escapeIri(relative.value)}>`;
|
|
1251
|
+
}
|
|
1252
|
+
return `<${escapeIri(iri)}>`;
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
/** Term kinds in writing order; anything else (a variable) sorts last. */
|
|
1256
|
+
const tagRank = {
|
|
1257
|
+
DefaultGraph: 0,
|
|
1258
|
+
NamedNode: 1,
|
|
1259
|
+
BlankNode: 2,
|
|
1260
|
+
Literal: 3,
|
|
1261
|
+
Triple: 4
|
|
1262
|
+
};
|
|
1263
|
+
/** The value of a numeric literal, or `NaN`. */
|
|
1264
|
+
const numericValue = (l) => {
|
|
1265
|
+
const dt = l.datatype.value;
|
|
1266
|
+
return dt === XSD_INTEGER || dt === XSD_DECIMAL || dt === XSD_DOUBLE ? Number(l.value) : NaN;
|
|
1267
|
+
};
|
|
1268
|
+
const compareTerms = (a, b) => {
|
|
1269
|
+
const ra = tagRank[a._tag] ?? 5;
|
|
1270
|
+
const rb = tagRank[b._tag] ?? 5;
|
|
1271
|
+
if (ra !== rb) return ra < rb ? -1 : 1;
|
|
1272
|
+
if (isLiteral(a) && isLiteral(b)) {
|
|
1273
|
+
const na = numericValue(a);
|
|
1274
|
+
const nb = numericValue(b);
|
|
1275
|
+
if (!Number.isNaN(na) && !Number.isNaN(nb) && na !== nb) return na < nb ? -1 : 1;
|
|
1276
|
+
}
|
|
1277
|
+
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
1278
|
+
};
|
|
1279
|
+
/** Prefix declarations by prefix name. */
|
|
1280
|
+
const byPrefixName = Order.mapInput(Order.String, ([prefix]) => prefix);
|
|
1281
|
+
/** Counts the namespaces of the IRIs in `t` (and in its datatype and triple terms). */
|
|
1282
|
+
const countNamespaces = (t, counts) => {
|
|
1283
|
+
if (isNamedNode(t)) {
|
|
1284
|
+
const i = Math.max(t.value.lastIndexOf("#"), t.value.lastIndexOf("/"));
|
|
1285
|
+
if (i <= 0) return;
|
|
1286
|
+
const ns = t.value.slice(0, i + 1);
|
|
1287
|
+
if (!isAbsoluteIri(ns) || Option.isNone(encodeLocalName(t.value.slice(i + 1)))) return;
|
|
1288
|
+
const found = MutableHashMap.get(counts, ns);
|
|
1289
|
+
if (Option.isSome(found)) found.value.count += 1;
|
|
1290
|
+
else MutableHashMap.set(counts, ns, { count: 1 });
|
|
1291
|
+
} else if (isLiteral(t)) {
|
|
1292
|
+
if (t.language === "" && t.datatype.value !== "http://www.w3.org/2001/XMLSchema#string") countNamespaces(t.datatype, counts);
|
|
1293
|
+
} else if (isTriple(t)) {
|
|
1294
|
+
countNamespaces(t.subject, counts);
|
|
1295
|
+
countNamespaces(t.predicate, counts);
|
|
1296
|
+
countNamespaces(t.object, counts);
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
/** Well-known namespaces by IRI, with their usual prefixes. */
|
|
1300
|
+
const knownPrefixes = MutableHashMap.fromIterable(Record.toEntries(commonPrefixes).map(([p, ns]) => [ns, p]));
|
|
1301
|
+
/**
|
|
1302
|
+
* Finds namespaces worth declaring: well-known vocabularies that are used,
|
|
1303
|
+
* plus any namespace used by at least two IRIs.
|
|
1304
|
+
*/
|
|
1305
|
+
const detectPrefixes = (quads, baseIri) => {
|
|
1306
|
+
const baseDir = Option.map(baseIri, (iri) => iri.slice(0, iri.lastIndexOf("/") + 1));
|
|
1307
|
+
const counts = MutableHashMap.empty();
|
|
1308
|
+
quads.forEach((q) => {
|
|
1309
|
+
countNamespaces(q.subject, counts);
|
|
1310
|
+
countNamespaces(q.predicate, counts);
|
|
1311
|
+
countNamespaces(q.object, counts);
|
|
1312
|
+
countNamespaces(q.graph, counts);
|
|
1313
|
+
});
|
|
1314
|
+
let n = 0;
|
|
1315
|
+
return Arr.flatMap(Arr.sort(counts, Order.mapInput(Order.String, ([ns]) => ns)), ([ns, { count }]) => {
|
|
1316
|
+
const name = MutableHashMap.get(knownPrefixes, ns);
|
|
1317
|
+
if (Option.isSome(name)) return [[name.value, ns]];
|
|
1318
|
+
if (Option.isSome(baseDir) && baseDir.value.includes("//") && ns.startsWith(baseDir.value)) return [];
|
|
1319
|
+
return count >= 2 ? [[`ns${n++}`, ns]] : [];
|
|
1320
|
+
});
|
|
1321
|
+
};
|
|
1322
|
+
/**
|
|
1323
|
+
* Normalises quads for writing: relabels blank nodes deterministically.
|
|
1324
|
+
*
|
|
1325
|
+
* @internal
|
|
1326
|
+
*/
|
|
1327
|
+
const prepare = (quads) => Array.from(relabel(fromIterable(quads), "b"));
|
|
1328
|
+
// src/turtle/internal/streamWriter.ts
|
|
1329
|
+
/**
|
|
1330
|
+
* An incremental Turtle / TriG writer.
|
|
1331
|
+
*
|
|
1332
|
+
* @internal
|
|
1333
|
+
*/
|
|
1334
|
+
/**
|
|
1335
|
+
* Groups consecutive statements by graph, subject and predicate but performs
|
|
1336
|
+
* no look-ahead (no inline blank nodes, lists or annotations), so it runs in
|
|
1337
|
+
* constant memory.
|
|
1338
|
+
*
|
|
1339
|
+
* @internal
|
|
1340
|
+
*/
|
|
1341
|
+
var StreamWriter = class {
|
|
1342
|
+
writerInstance = Option.none();
|
|
1343
|
+
/** The keys of the open graph block, statement and predicate. */
|
|
1344
|
+
graph = Option.none();
|
|
1345
|
+
subject = Option.none();
|
|
1346
|
+
predicate = Option.none();
|
|
1347
|
+
started = false;
|
|
1348
|
+
options;
|
|
1349
|
+
constructor(options) {
|
|
1350
|
+
this.options = options;
|
|
1351
|
+
}
|
|
1352
|
+
/** Created lazily so that option validation errors surface as failures. */
|
|
1353
|
+
get writer() {
|
|
1354
|
+
if (Option.isSome(this.writerInstance)) return this.writerInstance.value;
|
|
1355
|
+
const writer = new Writer({
|
|
1356
|
+
...this.options,
|
|
1357
|
+
autoPrefixes: false
|
|
1358
|
+
}, [], false);
|
|
1359
|
+
this.writerInstance = Option.some(writer);
|
|
1360
|
+
return writer;
|
|
1361
|
+
}
|
|
1362
|
+
/** The document header: base and all declared prefixes. */
|
|
1363
|
+
header() {
|
|
1364
|
+
this.writer;
|
|
1365
|
+
const sparql = this.options.sparqlDirectives;
|
|
1366
|
+
const out = Option.match(this.options.baseIri, {
|
|
1367
|
+
onNone: () => "",
|
|
1368
|
+
onSome: (iri) => {
|
|
1369
|
+
const escaped = escapeIri(iri);
|
|
1370
|
+
return sparql ? `BASE <${escaped}>\n` : `@base <${escaped}> .\n`;
|
|
1371
|
+
}
|
|
1372
|
+
}) + Option.match(this.options.prefixes, {
|
|
1373
|
+
onNone: () => "",
|
|
1374
|
+
onSome: (map) => Arr.sort(Arr.filter(Arr.fromIterable(map.prefixes), ([p, ns]) => isPrefixName(p) && isWritableIri(ns)), byPrefixName).map(([p, ns]) => {
|
|
1375
|
+
const iri = escapeIri(ns);
|
|
1376
|
+
return sparql ? `PREFIX ${p}: <${iri}>\n` : `@prefix ${p}: <${iri}> .\n`;
|
|
1377
|
+
}).join("")
|
|
1378
|
+
});
|
|
1379
|
+
return out === "" ? "" : `${out}\n`;
|
|
1380
|
+
}
|
|
1381
|
+
write(quads) {
|
|
1382
|
+
let out = "";
|
|
1383
|
+
if (!this.started) {
|
|
1384
|
+
this.started = true;
|
|
1385
|
+
out += this.header();
|
|
1386
|
+
}
|
|
1387
|
+
const indent = this.options.indent;
|
|
1388
|
+
const writer = this.writer;
|
|
1389
|
+
Iterable.forEach(quads, (q) => {
|
|
1390
|
+
checkQuad(q, this.options.trig);
|
|
1391
|
+
const graph = q.graph.key;
|
|
1392
|
+
if (Option.isNone(this.graph) || this.graph.value !== graph) {
|
|
1393
|
+
out += this.closeGraph();
|
|
1394
|
+
this.graph = Option.some(graph);
|
|
1395
|
+
if (!isDefaultGraph(q.graph)) out += `${writer.term(q.graph)} {\n`;
|
|
1396
|
+
}
|
|
1397
|
+
const pad = isDefaultGraph(q.graph) ? "" : indent;
|
|
1398
|
+
const object = writer.term(q.object);
|
|
1399
|
+
if (Option.isSome(this.subject) && this.subject.value === q.subject.key) {
|
|
1400
|
+
if (Option.isSome(this.predicate) && this.predicate.value === q.predicate.key) out += `, ${object}`;
|
|
1401
|
+
else {
|
|
1402
|
+
this.predicate = Option.some(q.predicate.key);
|
|
1403
|
+
out += ` ;\n${pad}${indent}${this.verb(q.predicate)} ${object}`;
|
|
1404
|
+
}
|
|
1405
|
+
} else {
|
|
1406
|
+
if (Option.isSome(this.subject)) out += " .\n";
|
|
1407
|
+
this.subject = Option.some(q.subject.key);
|
|
1408
|
+
this.predicate = Option.some(q.predicate.key);
|
|
1409
|
+
out += `${pad}${writer.term(q.subject)} ${this.verb(q.predicate)} ${object}`;
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
return out;
|
|
1413
|
+
}
|
|
1414
|
+
/** Closes any open statement and graph block. */
|
|
1415
|
+
end() {
|
|
1416
|
+
const head = this.started ? "" : this.header();
|
|
1417
|
+
this.started = true;
|
|
1418
|
+
return head + this.closeGraph();
|
|
1419
|
+
}
|
|
1420
|
+
verb(p) {
|
|
1421
|
+
return p.value === rdf.type.value ? "a" : this.writer.iri(p.value);
|
|
1422
|
+
}
|
|
1423
|
+
closeGraph() {
|
|
1424
|
+
let out = "";
|
|
1425
|
+
if (Option.isSome(this.subject)) out += " .\n";
|
|
1426
|
+
this.subject = Option.none();
|
|
1427
|
+
this.predicate = Option.none();
|
|
1428
|
+
if (Option.isSome(this.graph) && this.graph.value !== "") out += "}\n";
|
|
1429
|
+
this.graph = Option.none();
|
|
1430
|
+
return out;
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
// src/turtle/internal/serialize.ts
|
|
1434
|
+
const writerOptions = (syntax, options) => ({
|
|
1435
|
+
trig: syntax.trig,
|
|
1436
|
+
prefixes: Option.fromUndefinedOr(options?.prefixes),
|
|
1437
|
+
baseIri: Option.fromUndefinedOr(options?.baseIri),
|
|
1438
|
+
autoPrefixes: options?.autoPrefixes ?? false,
|
|
1439
|
+
sparqlDirectives: options?.sparqlDirectives ?? false,
|
|
1440
|
+
indent: options?.indent ?? " "
|
|
1441
|
+
});
|
|
1442
|
+
/** Maps what a serialisation threw (an `Error` or its string form) to an `RdfSerializeError`. */
|
|
1443
|
+
const toSerializeError = (syntax, error) => new RdfSerializeError({
|
|
1444
|
+
format: syntax.name,
|
|
1445
|
+
message: Predicate.isString(error) ? error : error.message
|
|
1446
|
+
});
|
|
1447
|
+
/** @internal */
|
|
1448
|
+
const serialize = (syntax, quads, options) => Effect.try({
|
|
1449
|
+
try: () => new Writer(writerOptions(syntax, options), prepare(quads)).write(),
|
|
1450
|
+
catch: (error) => toSerializeError(syntax, Predicate.isError(error) ? error : String(error))
|
|
1451
|
+
}).pipe(withSerializeSpan(Option.getOrUndefined(syntax.trace)));
|
|
1452
|
+
/** @internal */
|
|
1453
|
+
const serializeStream = (syntax) => (quads, options) => Stream.suspend(() => {
|
|
1454
|
+
const writer = new StreamWriter(writerOptions(syntax, options));
|
|
1455
|
+
const write = (f) => Effect.try({
|
|
1456
|
+
try: f,
|
|
1457
|
+
catch: (error) => toSerializeError(syntax, Predicate.isError(error) ? error : String(error))
|
|
1458
|
+
});
|
|
1459
|
+
return quads.pipe(Stream.chunks, Stream.mapEffect((chunk) => write(() => writer.write(chunk))), Stream.concat(Stream.fromEffect(write(() => writer.end()))), Stream.filter((s) => s !== ""));
|
|
1460
|
+
}).pipe(withStreamSpan(Option.getOrUndefined(syntax.trace), "serializeStream"));
|
|
1461
|
+
export { parseStream as a, parseQuads as i, serializeStream as n, parse as r, serialize as t };
|
|
1462
|
+
|
|
1463
|
+
//# sourceMappingURL=serialize-96KBvKaf.mjs.map
|