@graphty/graph-io 0.0.0 → 0.2.1
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 +250 -28
- package/dist/chunks/children-CL3Cy0ez.js +238 -0
- package/dist/chunks/children-CL3Cy0ez.js.map +1 -0
- package/dist/chunks/escape-DyI8JofU.js +938 -0
- package/dist/chunks/escape-DyI8JofU.js.map +1 -0
- package/dist/chunks/importer-CQnJuWJw.js +2987 -0
- package/dist/chunks/importer-CQnJuWJw.js.map +1 -0
- package/dist/chunks/importer-CpCpfbxr.js +2015 -0
- package/dist/chunks/importer-CpCpfbxr.js.map +1 -0
- package/dist/chunks/importer-DbnGYr3_.js +2342 -0
- package/dist/chunks/importer-DbnGYr3_.js.map +1 -0
- package/dist/chunks/importer-GozH8DkN.js +3050 -0
- package/dist/chunks/importer-GozH8DkN.js.map +1 -0
- package/dist/chunks/records-CGpxszm1.js +605 -0
- package/dist/chunks/records-CGpxszm1.js.map +1 -0
- package/dist/chunks/text-CajMdVFy.js +189 -0
- package/dist/chunks/text-CajMdVFy.js.map +1 -0
- package/dist/chunks/writer-DxSKC7TL.js +2842 -0
- package/dist/chunks/writer-DxSKC7TL.js.map +1 -0
- package/dist/csv.d.ts +1 -0
- package/dist/csv.js +1702 -0
- package/dist/csv.js.map +1 -0
- package/dist/dot.d.ts +1 -0
- package/dist/dot.js +8 -0
- package/dist/dot.js.map +1 -0
- package/dist/gexf.d.ts +1 -0
- package/dist/gexf.js +3466 -0
- package/dist/gexf.js.map +1 -0
- package/dist/gml.d.ts +1 -0
- package/dist/gml.js +2647 -0
- package/dist/gml.js.map +1 -0
- package/dist/graph-io.d.ts +1 -0
- package/dist/graph-io.js +790 -0
- package/dist/graph-io.js.map +1 -0
- package/dist/graphml.d.ts +1 -0
- package/dist/graphml.js +8 -0
- package/dist/graphml.js.map +1 -0
- package/dist/json.d.ts +1 -0
- package/dist/json.js +11 -0
- package/dist/json.js.map +1 -0
- package/dist/neo4j.d.ts +1 -0
- package/dist/neo4j.js +2046 -0
- package/dist/neo4j.js.map +1 -0
- package/dist/pajek.d.ts +1 -0
- package/dist/pajek.js +8 -0
- package/dist/pajek.js.map +1 -0
- package/dist/src/children.d.ts +134 -0
- package/dist/src/children.d.ts.map +1 -0
- package/dist/src/children.js +274 -0
- package/dist/src/children.js.map +1 -0
- package/dist/src/common/attributes.d.ts +229 -0
- package/dist/src/common/attributes.d.ts.map +1 -0
- package/dist/src/common/attributes.js +368 -0
- package/dist/src/common/attributes.js.map +1 -0
- package/dist/src/common/codes.d.ts +105 -0
- package/dist/src/common/codes.d.ts.map +1 -0
- package/dist/src/common/codes.js +107 -0
- package/dist/src/common/codes.js.map +1 -0
- package/dist/src/common/declared-types.d.ts +84 -0
- package/dist/src/common/declared-types.d.ts.map +1 -0
- package/dist/src/common/declared-types.js +326 -0
- package/dist/src/common/declared-types.js.map +1 -0
- package/dist/src/common/direction.d.ts +206 -0
- package/dist/src/common/direction.d.ts.map +1 -0
- package/dist/src/common/direction.js +370 -0
- package/dist/src/common/direction.js.map +1 -0
- package/dist/src/common/escape.d.ts +92 -0
- package/dist/src/common/escape.d.ts.map +1 -0
- package/dist/src/common/escape.js +212 -0
- package/dist/src/common/escape.js.map +1 -0
- package/dist/src/common/export.d.ts +249 -0
- package/dist/src/common/export.d.ts.map +1 -0
- package/dist/src/common/export.js +594 -0
- package/dist/src/common/export.js.map +1 -0
- package/dist/src/common/format.d.ts +59 -0
- package/dist/src/common/format.d.ts.map +1 -0
- package/dist/src/common/format.js +106 -0
- package/dist/src/common/format.js.map +1 -0
- package/dist/src/common/ids.d.ts +83 -0
- package/dist/src/common/ids.d.ts.map +1 -0
- package/dist/src/common/ids.js +158 -0
- package/dist/src/common/ids.js.map +1 -0
- package/dist/src/common/input.d.ts +100 -0
- package/dist/src/common/input.d.ts.map +1 -0
- package/dist/src/common/input.js +335 -0
- package/dist/src/common/input.js.map +1 -0
- package/dist/src/common/lists.d.ts +34 -0
- package/dist/src/common/lists.d.ts.map +1 -0
- package/dist/src/common/lists.js +185 -0
- package/dist/src/common/lists.js.map +1 -0
- package/dist/src/common/options.d.ts +108 -0
- package/dist/src/common/options.d.ts.map +1 -0
- package/dist/src/common/options.js +265 -0
- package/dist/src/common/options.js.map +1 -0
- package/dist/src/common/report.d.ts +187 -0
- package/dist/src/common/report.d.ts.map +1 -0
- package/dist/src/common/report.js +274 -0
- package/dist/src/common/report.js.map +1 -0
- package/dist/src/common/temporal.d.ts +71 -0
- package/dist/src/common/temporal.d.ts.map +1 -0
- package/dist/src/common/temporal.js +266 -0
- package/dist/src/common/temporal.js.map +1 -0
- package/dist/src/common/text.d.ts +104 -0
- package/dist/src/common/text.d.ts.map +1 -0
- package/dist/src/common/text.js +255 -0
- package/dist/src/common/text.js.map +1 -0
- package/dist/src/common/weights.d.ts +77 -0
- package/dist/src/common/weights.d.ts.map +1 -0
- package/dist/src/common/weights.js +156 -0
- package/dist/src/common/weights.js.map +1 -0
- package/dist/src/common/writer.d.ts +51 -0
- package/dist/src/common/writer.d.ts.map +1 -0
- package/dist/src/common/writer.js +108 -0
- package/dist/src/common/writer.js.map +1 -0
- package/dist/src/common/xml.d.ts +245 -0
- package/dist/src/common/xml.d.ts.map +1 -0
- package/dist/src/common/xml.js +942 -0
- package/dist/src/common/xml.js.map +1 -0
- package/dist/src/formats/csv/exporter.d.ts +70 -0
- package/dist/src/formats/csv/exporter.d.ts.map +1 -0
- package/dist/src/formats/csv/exporter.js +682 -0
- package/dist/src/formats/csv/exporter.js.map +1 -0
- package/dist/src/formats/csv/header.d.ts +66 -0
- package/dist/src/formats/csv/header.d.ts.map +1 -0
- package/dist/src/formats/csv/header.js +152 -0
- package/dist/src/formats/csv/header.js.map +1 -0
- package/dist/src/formats/csv/importer.d.ts +82 -0
- package/dist/src/formats/csv/importer.d.ts.map +1 -0
- package/dist/src/formats/csv/importer.js +849 -0
- package/dist/src/formats/csv/importer.js.map +1 -0
- package/dist/src/formats/csv/index.d.ts +60 -0
- package/dist/src/formats/csv/index.d.ts.map +1 -0
- package/dist/src/formats/csv/index.js +63 -0
- package/dist/src/formats/csv/index.js.map +1 -0
- package/dist/src/formats/csv/records.d.ts +188 -0
- package/dist/src/formats/csv/records.d.ts.map +1 -0
- package/dist/src/formats/csv/records.js +702 -0
- package/dist/src/formats/csv/records.js.map +1 -0
- package/dist/src/formats/csv/values.d.ts +105 -0
- package/dist/src/formats/csv/values.d.ts.map +1 -0
- package/dist/src/formats/csv/values.js +192 -0
- package/dist/src/formats/csv/values.js.map +1 -0
- package/dist/src/formats/dot/exporter.d.ts +52 -0
- package/dist/src/formats/dot/exporter.d.ts.map +1 -0
- package/dist/src/formats/dot/exporter.js +836 -0
- package/dist/src/formats/dot/exporter.js.map +1 -0
- package/dist/src/formats/dot/importer.d.ts +102 -0
- package/dist/src/formats/dot/importer.d.ts.map +1 -0
- package/dist/src/formats/dot/importer.js +1291 -0
- package/dist/src/formats/dot/importer.js.map +1 -0
- package/dist/src/formats/dot/index.d.ts +7 -0
- package/dist/src/formats/dot/index.d.ts.map +1 -0
- package/dist/src/formats/dot/index.js +7 -0
- package/dist/src/formats/dot/index.js.map +1 -0
- package/dist/src/formats/dot/names.d.ts +29 -0
- package/dist/src/formats/dot/names.d.ts.map +1 -0
- package/dist/src/formats/dot/names.js +28 -0
- package/dist/src/formats/dot/names.js.map +1 -0
- package/dist/src/formats/dot/tokenizer.d.ts +114 -0
- package/dist/src/formats/dot/tokenizer.d.ts.map +1 -0
- package/dist/src/formats/dot/tokenizer.js +341 -0
- package/dist/src/formats/dot/tokenizer.js.map +1 -0
- package/dist/src/formats/gexf/exporter.d.ts +56 -0
- package/dist/src/formats/gexf/exporter.d.ts.map +1 -0
- package/dist/src/formats/gexf/exporter.js +1395 -0
- package/dist/src/formats/gexf/exporter.js.map +1 -0
- package/dist/src/formats/gexf/importer.d.ts +73 -0
- package/dist/src/formats/gexf/importer.d.ts.map +1 -0
- package/dist/src/formats/gexf/importer.js +1880 -0
- package/dist/src/formats/gexf/importer.js.map +1 -0
- package/dist/src/formats/gexf/index.d.ts +96 -0
- package/dist/src/formats/gexf/index.d.ts.map +1 -0
- package/dist/src/formats/gexf/index.js +97 -0
- package/dist/src/formats/gexf/index.js.map +1 -0
- package/dist/src/formats/gexf/schema.d.ts +135 -0
- package/dist/src/formats/gexf/schema.d.ts.map +1 -0
- package/dist/src/formats/gexf/schema.js +323 -0
- package/dist/src/formats/gexf/schema.js.map +1 -0
- package/dist/src/formats/gml/exporter.d.ts +69 -0
- package/dist/src/formats/gml/exporter.d.ts.map +1 -0
- package/dist/src/formats/gml/exporter.js +1093 -0
- package/dist/src/formats/gml/exporter.js.map +1 -0
- package/dist/src/formats/gml/importer.d.ts +66 -0
- package/dist/src/formats/gml/importer.d.ts.map +1 -0
- package/dist/src/formats/gml/importer.js +1331 -0
- package/dist/src/formats/gml/importer.js.map +1 -0
- package/dist/src/formats/gml/index.d.ts +85 -0
- package/dist/src/formats/gml/index.d.ts.map +1 -0
- package/dist/src/formats/gml/index.js +88 -0
- package/dist/src/formats/gml/index.js.map +1 -0
- package/dist/src/formats/gml/syntax.d.ts +186 -0
- package/dist/src/formats/gml/syntax.d.ts.map +1 -0
- package/dist/src/formats/gml/syntax.js +467 -0
- package/dist/src/formats/gml/syntax.js.map +1 -0
- package/dist/src/formats/graphml/constants.d.ts +169 -0
- package/dist/src/formats/graphml/constants.d.ts.map +1 -0
- package/dist/src/formats/graphml/constants.js +165 -0
- package/dist/src/formats/graphml/constants.js.map +1 -0
- package/dist/src/formats/graphml/exporter.d.ts +34 -0
- package/dist/src/formats/graphml/exporter.d.ts.map +1 -0
- package/dist/src/formats/graphml/exporter.js +1176 -0
- package/dist/src/formats/graphml/exporter.js.map +1 -0
- package/dist/src/formats/graphml/importer.d.ts +31 -0
- package/dist/src/formats/graphml/importer.d.ts.map +1 -0
- package/dist/src/formats/graphml/importer.js +1607 -0
- package/dist/src/formats/graphml/importer.js.map +1 -0
- package/dist/src/formats/graphml/index.d.ts +8 -0
- package/dist/src/formats/graphml/index.d.ts.map +1 -0
- package/dist/src/formats/graphml/index.js +8 -0
- package/dist/src/formats/graphml/index.js.map +1 -0
- package/dist/src/formats/graphml/tree.d.ts +72 -0
- package/dist/src/formats/graphml/tree.d.ts.map +1 -0
- package/dist/src/formats/graphml/tree.js +290 -0
- package/dist/src/formats/graphml/tree.js.map +1 -0
- package/dist/src/formats/json/dialect.d.ts +125 -0
- package/dist/src/formats/json/dialect.d.ts.map +1 -0
- package/dist/src/formats/json/dialect.js +262 -0
- package/dist/src/formats/json/dialect.js.map +1 -0
- package/dist/src/formats/json/exporter.d.ts +89 -0
- package/dist/src/formats/json/exporter.d.ts.map +1 -0
- package/dist/src/formats/json/exporter.js +1358 -0
- package/dist/src/formats/json/exporter.js.map +1 -0
- package/dist/src/formats/json/importer.d.ts +108 -0
- package/dist/src/formats/json/importer.d.ts.map +1 -0
- package/dist/src/formats/json/importer.js +1838 -0
- package/dist/src/formats/json/importer.js.map +1 -0
- package/dist/src/formats/json/index.d.ts +8 -0
- package/dist/src/formats/json/index.d.ts.map +1 -0
- package/dist/src/formats/json/index.js +8 -0
- package/dist/src/formats/json/index.js.map +1 -0
- package/dist/src/formats/neo4j/exporter.d.ts +68 -0
- package/dist/src/formats/neo4j/exporter.d.ts.map +1 -0
- package/dist/src/formats/neo4j/exporter.js +1055 -0
- package/dist/src/formats/neo4j/exporter.js.map +1 -0
- package/dist/src/formats/neo4j/header.d.ts +52 -0
- package/dist/src/formats/neo4j/header.d.ts.map +1 -0
- package/dist/src/formats/neo4j/header.js +131 -0
- package/dist/src/formats/neo4j/header.js.map +1 -0
- package/dist/src/formats/neo4j/importer.d.ts +73 -0
- package/dist/src/formats/neo4j/importer.d.ts.map +1 -0
- package/dist/src/formats/neo4j/importer.js +932 -0
- package/dist/src/formats/neo4j/importer.js.map +1 -0
- package/dist/src/formats/neo4j/index.d.ts +79 -0
- package/dist/src/formats/neo4j/index.d.ts.map +1 -0
- package/dist/src/formats/neo4j/index.js +83 -0
- package/dist/src/formats/neo4j/index.js.map +1 -0
- package/dist/src/formats/pajek/exporter.d.ts +58 -0
- package/dist/src/formats/pajek/exporter.d.ts.map +1 -0
- package/dist/src/formats/pajek/exporter.js +825 -0
- package/dist/src/formats/pajek/exporter.js.map +1 -0
- package/dist/src/formats/pajek/importer.d.ts +88 -0
- package/dist/src/formats/pajek/importer.d.ts.map +1 -0
- package/dist/src/formats/pajek/importer.js +1047 -0
- package/dist/src/formats/pajek/importer.js.map +1 -0
- package/dist/src/formats/pajek/index.d.ts +7 -0
- package/dist/src/formats/pajek/index.d.ts.map +1 -0
- package/dist/src/formats/pajek/index.js +7 -0
- package/dist/src/formats/pajek/index.js.map +1 -0
- package/dist/src/formats/pajek/syntax.d.ts +112 -0
- package/dist/src/formats/pajek/syntax.d.ts.map +1 -0
- package/dist/src/formats/pajek/syntax.js +269 -0
- package/dist/src/formats/pajek/syntax.js.map +1 -0
- package/dist/src/index.d.ts +35 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +39 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/registry.d.ts +207 -0
- package/dist/src/registry.d.ts.map +1 -0
- package/dist/src/registry.js +481 -0
- package/dist/src/registry.js.map +1 -0
- package/dist/src/sniff.d.ts +104 -0
- package/dist/src/sniff.d.ts.map +1 -0
- package/dist/src/sniff.js +357 -0
- package/dist/src/sniff.js.map +1 -0
- package/dist/src/types.d.ts +238 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +29 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +122 -7
- package/src/children.ts +335 -0
- package/src/common/attributes.ts +520 -0
- package/src/common/codes.ts +153 -0
- package/src/common/declared-types.ts +374 -0
- package/src/common/direction.ts +518 -0
- package/src/common/escape.ts +231 -0
- package/src/common/export.ts +817 -0
- package/src/common/format.ts +111 -0
- package/src/common/ids.ts +176 -0
- package/src/common/input.ts +378 -0
- package/src/common/lists.ts +196 -0
- package/src/common/options.ts +377 -0
- package/src/common/report.ts +352 -0
- package/src/common/temporal.ts +302 -0
- package/src/common/text.ts +294 -0
- package/src/common/weights.ts +202 -0
- package/src/common/writer.ts +123 -0
- package/src/common/xml.ts +1053 -0
- package/src/formats/csv/exporter.ts +894 -0
- package/src/formats/csv/header.ts +172 -0
- package/src/formats/csv/importer.ts +1104 -0
- package/src/formats/csv/index.ts +88 -0
- package/src/formats/csv/records.ts +813 -0
- package/src/formats/csv/values.ts +224 -0
- package/src/formats/dot/exporter.ts +1014 -0
- package/src/formats/dot/importer.ts +1549 -0
- package/src/formats/dot/index.ts +7 -0
- package/src/formats/dot/names.ts +40 -0
- package/src/formats/dot/tokenizer.ts +384 -0
- package/src/formats/gexf/exporter.ts +1696 -0
- package/src/formats/gexf/importer.ts +2333 -0
- package/src/formats/gexf/index.ts +142 -0
- package/src/formats/gexf/schema.ts +361 -0
- package/src/formats/gml/exporter.ts +1404 -0
- package/src/formats/gml/importer.ts +1591 -0
- package/src/formats/gml/index.ts +128 -0
- package/src/formats/gml/syntax.ts +545 -0
- package/src/formats/graphml/constants.ts +225 -0
- package/src/formats/graphml/exporter.ts +1458 -0
- package/src/formats/graphml/importer.ts +2027 -0
- package/src/formats/graphml/index.ts +8 -0
- package/src/formats/graphml/tree.ts +318 -0
- package/src/formats/json/dialect.ts +317 -0
- package/src/formats/json/exporter.ts +1616 -0
- package/src/formats/json/importer.ts +2271 -0
- package/src/formats/json/index.ts +8 -0
- package/src/formats/neo4j/exporter.ts +1287 -0
- package/src/formats/neo4j/header.ts +156 -0
- package/src/formats/neo4j/importer.ts +1220 -0
- package/src/formats/neo4j/index.ts +116 -0
- package/src/formats/pajek/exporter.ts +1000 -0
- package/src/formats/pajek/importer.ts +1311 -0
- package/src/formats/pajek/index.ts +7 -0
- package/src/formats/pajek/syntax.ts +307 -0
- package/src/index.ts +244 -0
- package/src/registry.ts +617 -0
- package/src/sniff.ts +397 -0
- package/src/types.ts +262 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The untyped attribute columns of the CSV importer (design sections 5.1 and 5.4): every cell is
|
|
3
|
+
* parsed by the fixed lexical grammar and pushed as a scalar, the sink's per-column inference
|
|
4
|
+
* widens `bool -> i32 -> f64 -> string`, and a column whose sampled values are all text becomes a
|
|
5
|
+
* `dict` when its cardinality stays below half the sampled rows (the 1024-row heuristic of
|
|
6
|
+
* design section 5.4). The sample is the only buffering: at most DICT_SAMPLE_ROWS (row, text)
|
|
7
|
+
* pairs per column, flushed on the decision.
|
|
8
|
+
*
|
|
9
|
+
* An unquoted empty cell is unset (never written); a quoted empty cell is the empty string. A
|
|
10
|
+
* column whose every cell is unset is declared as a nullable string column at the end so the
|
|
11
|
+
* header survives a round trip. Inferred columns go through the shared TextCellWriter, which keeps
|
|
12
|
+
* the column's dtype the one the 5.1 grammar implies and the lexical form of numeric-looking cells
|
|
13
|
+
* that a widening to string would otherwise rewrite.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { type ColumnHandle, GraphFormatError, type GraphSink, INVALID_INDEX } from "@graphty/graph-format";
|
|
17
|
+
|
|
18
|
+
import { DICT_SAMPLE_ROWS, DictHeuristic } from "../../common/attributes.js";
|
|
19
|
+
import { type ImportReportBuilder } from "../../common/report.js";
|
|
20
|
+
import { inferTextDtype, parseTextCell, TextCellWriter } from "../../common/text.js";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One inferred attribute column of a node or edge table, written cell by cell.
|
|
24
|
+
*/
|
|
25
|
+
export class InferredColumn {
|
|
26
|
+
/** The column name in the sink. */
|
|
27
|
+
readonly name: string;
|
|
28
|
+
|
|
29
|
+
private readonly domain: "node" | "edge";
|
|
30
|
+
|
|
31
|
+
private readonly sink: GraphSink;
|
|
32
|
+
|
|
33
|
+
private readonly report: ImportReportBuilder;
|
|
34
|
+
|
|
35
|
+
private handle: ColumnHandle = INVALID_INDEX as ColumnHandle;
|
|
36
|
+
|
|
37
|
+
/** Whether values are pushed as text: a dict column, or a caller's string / dict column of the name. */
|
|
38
|
+
private text = false;
|
|
39
|
+
|
|
40
|
+
/** Whether the column was declared as a dict by this writer. */
|
|
41
|
+
private dict = false;
|
|
42
|
+
|
|
43
|
+
/** Whether the dtype decision was made; until then values are sampled. */
|
|
44
|
+
private decided = false;
|
|
45
|
+
|
|
46
|
+
/** Whether every sampled value so far is text under the lexical grammar (a dict candidate). */
|
|
47
|
+
private candidate = true;
|
|
48
|
+
|
|
49
|
+
private readonly heuristic: DictHeuristic;
|
|
50
|
+
|
|
51
|
+
/** The inferred-column writer, once the column was decided to be inferred (neither dict nor a caller's). */
|
|
52
|
+
private writer: TextCellWriter | null = null;
|
|
53
|
+
|
|
54
|
+
private readonly pendingRows: number[] = [];
|
|
55
|
+
|
|
56
|
+
private readonly pendingTexts: string[] = [];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Create a column writer; nothing is declared until the first value or finish().
|
|
60
|
+
* @param name - the column name
|
|
61
|
+
* @param domain - node or edge
|
|
62
|
+
* @param sink - the sink
|
|
63
|
+
* @param report - the report a refused sampled value is recorded in (the flush has no line numbers)
|
|
64
|
+
* @param sampleRows - rows sampled before the dict decision; DICT_SAMPLE_ROWS by default
|
|
65
|
+
*/
|
|
66
|
+
constructor(
|
|
67
|
+
name: string,
|
|
68
|
+
domain: "node" | "edge",
|
|
69
|
+
sink: GraphSink,
|
|
70
|
+
report: ImportReportBuilder,
|
|
71
|
+
sampleRows: number = DICT_SAMPLE_ROWS,
|
|
72
|
+
) {
|
|
73
|
+
this.name = name;
|
|
74
|
+
this.domain = domain;
|
|
75
|
+
this.sink = sink;
|
|
76
|
+
this.report = report;
|
|
77
|
+
this.heuristic = new DictHeuristic(sampleRows);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Whether the column was declared as a dict.
|
|
82
|
+
* @returns true after a dict decision
|
|
83
|
+
*/
|
|
84
|
+
get isDict(): boolean {
|
|
85
|
+
return this.dict;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Write one set cell.
|
|
90
|
+
* @param row - the node or edge index
|
|
91
|
+
* @param text - the cell text (the empty string for a quoted empty cell)
|
|
92
|
+
*/
|
|
93
|
+
write(row: number, text: string): void {
|
|
94
|
+
if (this.decided) {
|
|
95
|
+
this.push(row, text);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.pendingRows.push(row);
|
|
99
|
+
this.pendingTexts.push(text);
|
|
100
|
+
if (this.candidate && inferTextDtype(text) !== "string") {
|
|
101
|
+
this.candidate = false;
|
|
102
|
+
}
|
|
103
|
+
const full = this.heuristic.observe(text);
|
|
104
|
+
if (full || !this.candidate) {
|
|
105
|
+
this.decide();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Decide an undecided column from what was sampled (or declare an all-empty column as string)
|
|
111
|
+
* and flush the sample. Call once at the end of the input.
|
|
112
|
+
*/
|
|
113
|
+
finish(): void {
|
|
114
|
+
if (!this.decided) {
|
|
115
|
+
this.decide();
|
|
116
|
+
}
|
|
117
|
+
if (this.handle === INVALID_INDEX) {
|
|
118
|
+
this.handle = this.lookup();
|
|
119
|
+
if (this.handle === INVALID_INDEX) {
|
|
120
|
+
this.handle = this.declare("string");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Make the dtype decision: a dict when every sampled value is text and the cardinality is low
|
|
127
|
+
* and no column of the name exists yet; inference otherwise. A column the sink already holds
|
|
128
|
+
* (a caller's) receives the cell text when it is a string or dict column and the parsed value
|
|
129
|
+
* otherwise. The sample is flushed either way; a sampled value the sink refuses (a caller's
|
|
130
|
+
* typed column of the name) is recorded as an issue of this column and the flush continues.
|
|
131
|
+
*/
|
|
132
|
+
private decide(): void {
|
|
133
|
+
this.decided = true;
|
|
134
|
+
const existing = this.lookup();
|
|
135
|
+
if (existing !== INVALID_INDEX) {
|
|
136
|
+
this.handle = existing;
|
|
137
|
+
this.text = this.holdsText();
|
|
138
|
+
} else if (this.candidate && this.heuristic.decide() === "dict") {
|
|
139
|
+
this.dict = true;
|
|
140
|
+
this.text = true;
|
|
141
|
+
this.handle = this.declare("dict");
|
|
142
|
+
} else {
|
|
143
|
+
this.writer = new TextCellWriter(this.name, this.domain, this.sink, this.report);
|
|
144
|
+
}
|
|
145
|
+
const rows = this.pendingRows;
|
|
146
|
+
const texts = this.pendingTexts;
|
|
147
|
+
for (let i = 0; i < rows.length; i++) {
|
|
148
|
+
try {
|
|
149
|
+
this.push(rows[i], texts[i]);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
this.report.recordError(err, { element: this.name });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
rows.length = 0;
|
|
155
|
+
texts.length = 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Push one value: text into a dict or a caller's text column, the parsed scalar into a caller's
|
|
160
|
+
* typed column, and everything else through the inferred-column writer.
|
|
161
|
+
* @param row - the node or edge index
|
|
162
|
+
* @param text - the cell text
|
|
163
|
+
*/
|
|
164
|
+
private push(row: number, text: string): void {
|
|
165
|
+
if (this.writer !== null) {
|
|
166
|
+
this.writer.write(row, text);
|
|
167
|
+
this.handle = this.writer.column;
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const value: unknown = this.text ? text : parseTextCell(text);
|
|
171
|
+
this.set(this.handle, row, value);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Set a cell in the sink's table for this domain.
|
|
176
|
+
* @param column - the handle or name
|
|
177
|
+
* @param row - the row
|
|
178
|
+
* @param value - the value
|
|
179
|
+
*/
|
|
180
|
+
private set(column: ColumnHandle | string, row: number, value: unknown): void {
|
|
181
|
+
if (this.domain === "node") {
|
|
182
|
+
this.sink.setNodeValue(column, row, value);
|
|
183
|
+
} else {
|
|
184
|
+
this.sink.setEdgeValue(column, row, value);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The sink's handle for this column's name.
|
|
190
|
+
* @returns the handle, or INVALID_INDEX when the sink has no such column yet
|
|
191
|
+
*/
|
|
192
|
+
private lookup(): ColumnHandle {
|
|
193
|
+
return this.domain === "node" ? this.sink.nodeColumn(this.name) : this.sink.edgeColumn(this.name);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Whether the sink's existing column of this name is a string or dict column, probed through
|
|
198
|
+
* the sink's declare (the same shape returns the existing handle, another is E_COLUMN_EXISTS).
|
|
199
|
+
* @returns true when cell text is what the column holds
|
|
200
|
+
*/
|
|
201
|
+
private holdsText(): boolean {
|
|
202
|
+
for (const dtype of ["string", "dict"] as const) {
|
|
203
|
+
try {
|
|
204
|
+
this.declare(dtype);
|
|
205
|
+
return true;
|
|
206
|
+
} catch (err) {
|
|
207
|
+
if (!(err instanceof GraphFormatError) || err.code !== "E_COLUMN_EXISTS") {
|
|
208
|
+
throw err;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Declare the column with a fixed dtype.
|
|
217
|
+
* @param dtype - dict or string
|
|
218
|
+
* @returns the handle
|
|
219
|
+
*/
|
|
220
|
+
private declare(dtype: "dict" | "string"): ColumnHandle {
|
|
221
|
+
const decl = { name: this.name, dtype, nullable: true, origin: { format: "csv" } };
|
|
222
|
+
return this.domain === "node" ? this.sink.declareNodeColumn(decl) : this.sink.declareEdgeColumn(decl);
|
|
223
|
+
}
|
|
224
|
+
}
|