Export Content with Entity Annotations
User Intent
Operation
Prerequisites
Complete Code Example (TypeScript)
import { Graphlit } from 'graphlit-client';
import * as fs from 'fs';
const graphlit = new Graphlit();
// Get content with entities
const content = await graphlit.getContent('content-id');
// Prepare export data
const exportData = {
id: content.content.id,
name: content.content.name,
type: content.content.type,
creationDate: content.content.creationDate,
text: content.content.markdown,
entities: content.content.observations?.map(obs => ({
type: obs.type,
name: obs.observable.name,
id: obs.observable.id,
occurrences: obs.occurrences?.map(occ => ({
confidence: occ.confidence,
pageIndex: occ.pageIndex,
boundingBox: occ.boundingBox,
startTime: occ.startTime,
endTime: occ.endTime
}))
})) || []
};
// Export as JSON
fs.writeFileSync('export.json', JSON.stringify(exportData, null, 2));
console.log('Exported with entity annotations');
// Export as CSV (flattened)
const csvRows = [
['Entity Type', 'Entity Name', 'Confidence', 'Page', 'Document'].join(',')
];
content.content.observations?.forEach(obs => {
obs.occurrences?.forEach(occ => {
csvRows.push([
obs.type,
obs.observable.name,
occ.confidence.toFixed(2),
occ.pageIndex?.toString() || '',
content.content.name
].join(','));
});
});
fs.writeFileSync('export.csv', csvRows.join('\n'));
console.log('Exported as CSV');Export Formats
JSON (Full Fidelity)
CSV (Tabular)
XML (Structured)
Database (Structured Storage)
Use Cases
Developer Hints
Last updated