MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / printTokens

Function printTokens

document-ai/process-document-ocr.js:131–144  ·  view source on GitHub ↗
(tokens, text)

Source from the content-addressed store, hash-verified

129 };
130
131 const printTokens = (tokens, text) => {
132 console.log(` ${tokens.length} tokens detected:`);
133 const firstTokenText = getText(tokens[0].layout.textAnchor, text);
134 console.log(` First token text: ${JSON.stringify(firstTokenText)}`);
135 const firstTokenBreakType = tokens[0].detectedBreak.type;
136 console.log(` First token break type: ${firstTokenBreakType}`);
137 const lastTokenText = getText(
138 tokens[tokens.length - 1].layout.textAnchor,
139 text
140 );
141 console.log(` Last token text: ${JSON.stringify(lastTokenText)}`);
142 const lastTokenBreakType = tokens[tokens.length - 1].detectedBreak.type;
143 console.log(` Last token break type: ${lastTokenBreakType}`);
144 };
145
146 // Extract shards from the text field
147 const getText = (textAnchor, text) => {

Callers 1

processDocumentFunction · 0.85

Calls 1

getTextFunction · 0.70

Tested by

no test coverage detected