parsing

package
v0.1.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ReferenceAdjudicationSchemaVersion = "1"

Variables

This section is empty.

Functions

func AppendReferenceAdjudication

func AppendReferenceAdjudication(path string, record ReferenceAdjudication) error

func ValidReferenceAdjudicationDecision

func ValidReferenceAdjudicationDecision(decision string) bool

Types

type AdjudicatedReferenceItem

type AdjudicatedReferenceItem struct {
	Index     int                    `json:"index"`
	Status    string                 `json:"status"`
	Reference Reference              `json:"reference"`
	Decision  *ReferenceAdjudication `json:"decision,omitempty"`
}

type AnyStyleReferenceParser

type AnyStyleReferenceParser struct {
	Runner  CommandRunner
	Version string
}

AnyStyleReferenceParser adapts Anystyle-like JSON reference output into ParsedDocument references.

func (AnyStyleReferenceParser) ParseReferences

func (p AnyStyleReferenceParser) ParseReferences(ctx context.Context, paperID string, bibliography []byte) (ParsedDocument, error)

type ArbitrationDecisionInput

type ArbitrationDecisionInput struct {
	AcceptedParser string
	Reason         string
	Reviewer       string
}

type CERMINEXMLParser

type CERMINEXMLParser struct{ Version string }

func (CERMINEXMLParser) Parse

func (p CERMINEXMLParser) Parse(ctx context.Context, data []byte, options ParseOptions) (ParsedDocument, error)

type CitationSpan

type CitationSpan struct {
	ID             string     `json:"id"`
	PassageID      string     `json:"passageId,omitempty"`
	Text           string     `json:"text"`
	Offset         TextOffset `json:"offset"`
	ReferenceIndex int        `json:"referenceIndex"`
	Confidence     float64    `json:"confidence,omitempty"`
}

CitationSpan records a citation mention and its stable offset in parsed text.

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, input []byte) ([]byte, error)
}

CommandRunner runs an optional external parser command.

type ComparisonReport

type ComparisonReport struct {
	PaperID        string             `json:"paperId"`
	Documents      []ParserRunSummary `json:"documents"`
	Candidates     []ParserCandidate  `json:"candidates"`
	SectionDelta   int                `json:"sectionDelta"`
	PassageDelta   int                `json:"passageDelta"`
	ReferenceDelta int                `json:"referenceDelta"`
	WarningCount   int                `json:"warningCount"`
	TitleMismatch  bool               `json:"titleMismatch"`
	RecommendedUse string             `json:"recommendedUse"`
}

ComparisonReport summarizes differences between parser outputs for the same paper.

func CompareParsedDocuments

func CompareParsedDocuments(docs []ParsedDocument) ComparisonReport

CompareParsedDocuments creates a deterministic parser comparison/fallback report.

type ExecCommandRunner

type ExecCommandRunner struct{ Command []string }

ExecCommandRunner invokes an external command and passes the bibliography on stdin.

func (ExecCommandRunner) Run

func (r ExecCommandRunner) Run(ctx context.Context, input []byte) ([]byte, error)

type FieldComparison

type FieldComparison struct {
	Field        string             `json:"field"`
	ParserValues []ParserFieldValue `json:"parserValues"`
}

type FieldScore

type FieldScore struct {
	ParserName string  `json:"parserName"`
	Score      float64 `json:"score"`
	Reason     string  `json:"reason"`
}

type GROBIDClient

type GROBIDClient struct {
	// contains filtered or unexported fields
}

GROBIDClient parses PDFs through a GROBID endpoint.

func NewGROBIDClient

func NewGROBIDClient(options GROBIDClientOptions) GROBIDClient

NewGROBIDClient creates a GROBID parser adapter.

func (GROBIDClient) Parse

func (c GROBIDClient) Parse(ctx context.Context, pdf []byte, options ParseOptions) (ParsedDocument, error)

Parse sends a PDF to GROBID and normalizes the returned TEI.

type GROBIDClientOptions

type GROBIDClientOptions struct {
	BaseURL     string
	Timeout     time.Duration
	Version     string
	MaxTEIBytes int64
}

GROBIDClientOptions configures the GROBID parser adapter.

type LayeredAnnotation

type LayeredAnnotation struct {
	ID         string     `json:"id"`
	Layer      string     `json:"layer"`
	Label      string     `json:"label,omitempty"`
	Text       string     `json:"text,omitempty"`
	Offset     TextOffset `json:"offset"`
	ParserName string     `json:"parserName,omitempty"`
	Confidence float64    `json:"confidence,omitempty"`
}

LayeredAnnotation records parser layer output such as section, paragraph, reference, or table annotations.

type MultiSourceReferenceNormalizationReport

type MultiSourceReferenceNormalizationReport struct {
	PaperID        string                         `json:"paperId"`
	ParserName     string                         `json:"parserName,omitempty"`
	ParserVersion  string                         `json:"parserVersion,omitempty"`
	Sources        []string                       `json:"sources"`
	SourceReports  []ReferenceNormalizationReport `json:"sourceReports"`
	Matches        []ReferenceMatch               `json:"matches"`
	AmbiguityQueue []ReferenceReviewItem          `json:"ambiguityQueue,omitempty"`
}

MultiSourceReferenceNormalizationReport combines reference normalization across source connectors.

func NormalizeParsedReferencesAcrossConnectors

func NormalizeParsedReferencesAcrossConnectors(ctx context.Context, connectors []sources.SourceConnector, doc ParsedDocument) (MultiSourceReferenceNormalizationReport, error)

NormalizeParsedReferencesAcrossConnectors runs reviewer-visible normalization across Crossref/OpenAlex/Semantic Scholar-style connectors.

func (MultiSourceReferenceNormalizationReport) HasSource

type PaperMageJSONParser

type PaperMageJSONParser struct{}

PaperMageJSONParser adapts externally generated PaperMage-style layer JSON into ParsedDocument.

func (PaperMageJSONParser) Parse

func (p PaperMageJSONParser) Parse(ctx context.Context, data []byte, options ParseOptions) (ParsedDocument, error)

Parse maps a conservative PaperMage layer export into ResearchForge's parsed-document model.

type ParseOptions

type ParseOptions struct {
	PaperID string
}

ParseOptions configures one parse request.

type ParsedAuthor

type ParsedAuthor struct {
	Given  string
	Family string
}

ParsedAuthor is a TEI-normalized author.

type ParsedDocument

type ParsedDocument struct {
	SchemaVersion         string
	PaperID               string
	ParserName            string
	ParserVersion         string
	Title                 string
	TitleOffset           TextOffset
	Authors               []ParsedAuthor
	Abstract              string
	AbstractOffset        TextOffset
	Sections              []Section
	References            []Reference
	Warnings              []string
	ParserConfidence      float64
	LayeredAnnotations    []LayeredAnnotation
	CitationSpans         []CitationSpan
	ReconciliationOutputs []ParserReconciliationOutput
}

ParsedDocument is normalized structured paper content.

func EnrichParsedDocumentModel

func EnrichParsedDocumentModel(doc ParsedDocument) ParsedDocument

EnrichParsedDocumentModel fills deterministic local offsets, layer annotations, citation spans, and parser confidence.

type ParserAdapter

type ParserAdapter interface {
	Parse(context.Context, []byte, ParseOptions) (ParsedDocument, error)
}

ParserAdapter parses a source document into a structured ParsedDocument.

type ParserArbitrationDecision

type ParserArbitrationDecision struct {
	AcceptedParser           string `json:"acceptedParser"`
	Reason                   string `json:"reason"`
	Reviewer                 string `json:"reviewer,omitempty"`
	ReviewerApprovalRequired bool   `json:"reviewerApprovalRequired"`
}

type ParserArbitrationReport

type ParserArbitrationReport struct {
	SchemaVersion         string                       `json:"schemaVersion"`
	PaperID               string                       `json:"paperId"`
	FieldScores           map[string][]FieldScore      `json:"fieldScores"`
	Comparisons           []FieldComparison            `json:"comparisons"`
	WarningComparison     []ParserWarnings             `json:"warningComparison"`
	ConflictReviewQueue   []ParserConflictReviewItem   `json:"conflictReviewQueue,omitempty"`
	ReconciliationOutputs []ParserReconciliationOutput `json:"reconciliationOutputs"`
	Decision              ParserArbitrationDecision    `json:"decision"`
}

type ParserBenchmarkFixture

type ParserBenchmarkFixture struct {
	ParserName         string
	FixtureID          string
	CorrectFields      int
	TotalFields        int
	ActiveMaintenance  bool
	HistoricalFallback bool
}

func DefaultParserBenchmarkFixtures

func DefaultParserBenchmarkFixtures() []ParserBenchmarkFixture

type ParserCandidate

type ParserCandidate struct {
	ParserName          string `json:"parserName"`
	CoverageScore       int    `json:"coverageScore"`
	MaintenanceRisk     string `json:"maintenanceRisk"`
	DependencyFootprint string `json:"dependencyFootprint"`
	LicensePolicy       string `json:"licensePolicy"`
}

ParserCandidate scores parser output coverage and fallback risk for reviewer triage.

type ParserConflictReviewItem

type ParserConflictReviewItem struct {
	Field        string             `json:"field"`
	Reason       string             `json:"reason"`
	ParserValues []ParserFieldValue `json:"parserValues"`
}

type ParserFallbackDecision

type ParserFallbackDecision struct {
	OrderedParsers         []string         `json:"orderedParsers"`
	ConflictReviewRequired bool             `json:"conflictReviewRequired"`
	NextAction             string           `json:"nextAction"`
	Comparison             ComparisonReport `json:"comparison"`
}

type ParserFallbackPolicy

type ParserFallbackPolicy struct {
	Parsers             []string `json:"parsers"`
	ReviewerRequired    bool     `json:"reviewerRequired"`
	AutoAcceptConflicts bool     `json:"autoAcceptConflicts"`
}

func DefaultParserFallbackPolicy

func DefaultParserFallbackPolicy() ParserFallbackPolicy

func (ParserFallbackPolicy) HasParser

func (p ParserFallbackPolicy) HasParser(name string) bool

func (ParserFallbackPolicy) Plan

type ParserFieldValue

type ParserFieldValue struct {
	ParserName string     `json:"parserName"`
	RawText    string     `json:"rawText"`
	Offset     TextOffset `json:"offset"`
}

type ParserMaintenanceRisk

type ParserMaintenanceRisk struct {
	ParserName         string  `json:"parserName"`
	FixtureCount       int     `json:"fixtureCount"`
	Accuracy           float64 `json:"accuracy"`
	ActiveMaintenance  bool    `json:"activeMaintenance"`
	HistoricalFallback bool    `json:"historicalFallback"`
	RiskLevel          string  `json:"riskLevel"`
	ReviewerGate       string  `json:"reviewerGate"`
	EnableFallback     bool    `json:"enableFallback"`
}

type ParserMaintenanceRiskReport

type ParserMaintenanceRiskReport struct {
	SchemaVersion string                  `json:"schemaVersion"`
	Parsers       []ParserMaintenanceRisk `json:"parsers"`
}

func BuildParserMaintenanceRiskReport

func BuildParserMaintenanceRiskReport(fixtures []ParserBenchmarkFixture) ParserMaintenanceRiskReport

func (ParserMaintenanceRiskReport) HasParser

func (r ParserMaintenanceRiskReport) HasParser(parser string) bool

func (ParserMaintenanceRiskReport) Parser

type ParserOutputPolicy

type ParserOutputPolicy struct {
	ParserName         string   `json:"parserName"`
	ParserSource       string   `json:"parserSource"`
	LicenseConstraints string   `json:"licenseConstraints"`
	Shareability       string   `json:"shareability"`
	ProvenanceFields   []string `json:"provenanceFields"`
}

type ParserOutputPolicyRegistry

type ParserOutputPolicyRegistry struct {
	SchemaVersion string               `json:"schemaVersion"`
	Policies      []ParserOutputPolicy `json:"policies"`
}

func DefaultParserOutputPolicies

func DefaultParserOutputPolicies() ParserOutputPolicyRegistry

func (ParserOutputPolicyRegistry) MustPolicy

func (r ParserOutputPolicyRegistry) MustPolicy(parserName string) ParserOutputPolicy

func (ParserOutputPolicyRegistry) Policy

func (r ParserOutputPolicyRegistry) Policy(parserName string) (ParserOutputPolicy, bool)

type ParserQualityConflict

type ParserQualityConflict struct {
	Field  string   `json:"field"`
	Values []string `json:"values"`
	Status string   `json:"status"`
}

type ParserQualityReport

type ParserQualityReport struct {
	SchemaVersion      string                  `json:"schemaVersion"`
	PaperID            string                  `json:"paperId"`
	ParserRuns         []ParserQualityRun      `json:"parserRuns"`
	MissingParsers     []string                `json:"missingParsers"`
	FieldConfidence    map[string]float64      `json:"fieldConfidence"`
	Conflicts          []ParserQualityConflict `json:"conflicts"`
	ReviewerRequired   bool                    `json:"reviewerRequired"`
	AutoAcceptedFields bool                    `json:"autoAcceptedFields"`
	RecommendedAction  string                  `json:"recommendedAction"`
}

func BuildParserQualityReport

func BuildParserQualityReport(docs []ParsedDocument) ParserQualityReport

func (ParserQualityReport) HasParser

func (r ParserQualityReport) HasParser(parser string) bool

type ParserQualityRun

type ParserQualityRun struct {
	ParserName       string  `json:"parserName"`
	ParserVersion    string  `json:"parserVersion"`
	TitlePresent     bool    `json:"titlePresent"`
	Sections         int     `json:"sections"`
	Passages         int     `json:"passages"`
	References       int     `json:"references"`
	ReferenceDOIs    int     `json:"referenceDois"`
	Warnings         int     `json:"warnings"`
	ParserConfidence float64 `json:"parserConfidence"`
	QualityScore     float64 `json:"qualityScore"`
}

type ParserReconciliationAlt

type ParserReconciliationAlt struct {
	ParserName string     `json:"parserName"`
	Value      string     `json:"value"`
	Offset     TextOffset `json:"offset"`
	Warnings   []string   `json:"warnings,omitempty"`
}

type ParserReconciliationOutput

type ParserReconciliationOutput struct {
	Field          string                    `json:"field"`
	AcceptedParser string                    `json:"acceptedParser"`
	AcceptedValue  string                    `json:"acceptedValue"`
	Reason         string                    `json:"reason"`
	Alternatives   []ParserReconciliationAlt `json:"alternatives,omitempty"`
}

ParserReconciliationOutput records field-level multi-parser reconciliation.

type ParserRunManifest

type ParserRunManifest struct {
	SchemaVersion            string   `json:"schemaVersion"`
	PaperID                  string   `json:"paperId"`
	ParserName               string   `json:"parserName"`
	ParserVersion            string   `json:"parserVersion"`
	ParserSource             string   `json:"parserSource"`
	OutputKind               string   `json:"outputKind"`
	Command                  []string `json:"command,omitempty"`
	InputChecksum            string   `json:"inputChecksum"`
	OutputChecksum           string   `json:"outputChecksum"`
	ParsedPath               string   `json:"parsedPath"`
	LicenseConstraints       string   `json:"licenseConstraints"`
	Shareability             string   `json:"shareability"`
	ProvenanceFields         []string `json:"provenanceFields"`
	ReviewerApprovalRequired bool     `json:"reviewerApprovalRequired"`
	Sections                 int      `json:"sections"`
	Passages                 int      `json:"passages"`
	References               int      `json:"references"`
	Warnings                 []string `json:"warnings,omitempty"`
}

ParserRunManifest records auditable parser-run provenance and layer counts.

func NewParserRunManifest

func NewParserRunManifest(doc ParsedDocument, input []byte, parsedPath string) ParserRunManifest

NewParserRunManifest summarizes one parser output for reproducibility and comparison.

func NewParserRunManifestWithOutput

func NewParserRunManifestWithOutput(doc ParsedDocument, input, output []byte, parsedPath string, command []string) ParserRunManifest

type ParserRunSummary

type ParserRunSummary struct {
	ParserName    string `json:"parserName"`
	ParserVersion string `json:"parserVersion"`
	Title         string `json:"title"`
	Sections      int    `json:"sections"`
	Passages      int    `json:"passages"`
	References    int    `json:"references"`
	Warnings      int    `json:"warnings"`
}

ParserRunSummary records comparable parser output counts.

type ParserWarnings

type ParserWarnings struct {
	ParserName string   `json:"parserName"`
	Warnings   []string `json:"warnings"`
}

type Passage

type Passage struct {
	ID                 string
	PaperID            string
	SectionID          string
	Text               string
	Offset             TextOffset
	ParserConfidence   float64
	LayeredAnnotations []LayeredAnnotation
	CitationSpans      []CitationSpan
}

Passage is one retrievable section passage.

type Reference

type Reference struct {
	Title      string
	DOI        string
	Raw        string
	Confidence float64
	Offset     TextOffset
}

Reference is one parsed bibliography reference.

type ReferenceAdjudication

type ReferenceAdjudication struct {
	SchemaVersion  string              `json:"schemaVersion"`
	ID             string              `json:"id"`
	PaperID        string              `json:"paperId"`
	ReferenceIndex int                 `json:"referenceIndex"`
	Decision       string              `json:"decision"`
	Reviewer       string              `json:"reviewer"`
	Reason         string              `json:"reason"`
	Original       Reference           `json:"original"`
	Match          *ReferenceMatch     `json:"match,omitempty"`
	Correction     ReferenceCorrection `json:"correction,omitempty"`
	ProvenanceRef  string              `json:"provenanceRef,omitempty"`
	CreatedAt      string              `json:"createdAt"`
}

func LoadReferenceAdjudications

func LoadReferenceAdjudications(path string) ([]ReferenceAdjudication, error)

func NewReferenceAdjudication

func NewReferenceAdjudication(doc ParsedDocument, index int, decision, reviewer, reason string, correction ReferenceCorrection) (ReferenceAdjudication, error)

type ReferenceAdjudicationReport

type ReferenceAdjudicationReport struct {
	PaperID    string                     `json:"paperId"`
	Items      []AdjudicatedReferenceItem `json:"items"`
	Accepted   int                        `json:"accepted"`
	Corrected  int                        `json:"corrected"`
	Rejected   int                        `json:"rejected"`
	Deferred   int                        `json:"deferred"`
	Unreviewed int                        `json:"unreviewed"`
}

type ReferenceAmbiguityExport

type ReferenceAmbiguityExport struct {
	SchemaVersion string                        `json:"schemaVersion"`
	PaperID       string                        `json:"paperId"`
	Items         []ReferenceAmbiguityQueueItem `json:"items"`
}

func ExportReferenceAmbiguityQueue

func ExportReferenceAmbiguityQueue(doc ParsedDocument, matches []ReferenceMatch, records []ReferenceAdjudication) ReferenceAmbiguityExport

type ReferenceAmbiguityQueueItem

type ReferenceAmbiguityQueueItem struct {
	Index          int    `json:"index"`
	Status         string `json:"status"`
	Title          string `json:"title,omitempty"`
	DOI            string `json:"doi,omitempty"`
	Raw            string `json:"raw,omitempty"`
	ParserName     string `json:"parserName,omitempty"`
	ParserVersion  string `json:"parserVersion,omitempty"`
	Source         string `json:"source,omitempty"`
	SourceID       string `json:"sourceId,omitempty"`
	Reason         string `json:"reason,omitempty"`
	ProvenanceRef  string `json:"provenanceRef,omitempty"`
	ResponseRawRef string `json:"responseRawRef,omitempty"`
}

type ReferenceCorrection

type ReferenceCorrection struct {
	Title string `json:"title,omitempty"`
	DOI   string `json:"doi,omitempty"`
	Raw   string `json:"raw,omitempty"`
}

type ReferenceMatch

type ReferenceMatch struct {
	Index            int                 `json:"index"`
	ParserName       string              `json:"parserName,omitempty"`
	ParserVersion    string              `json:"parserVersion,omitempty"`
	Title            string              `json:"title"`
	DOI              string              `json:"doi,omitempty"`
	Raw              string              `json:"raw,omitempty"`
	ParserConfidence float64             `json:"parserConfidence,omitempty"`
	Matched          bool                `json:"matched"`
	Source           string              `json:"source,omitempty"`
	SourceID         string              `json:"sourceId,omitempty"`
	MatchedDOI       string              `json:"matchedDoi,omitempty"`
	MatchedTitle     string              `json:"matchedTitle,omitempty"`
	MatchConfidence  float64             `json:"matchConfidence,omitempty"`
	CandidateCount   int                 `json:"candidateCount"`
	Ambiguous        bool                `json:"ambiguous"`
	AmbiguityReason  string              `json:"ambiguityReason,omitempty"`
	Request          sources.SourceQuery `json:"request"`
	ResponseRawRef   string              `json:"responseRawRef,omitempty"`
	Metadata         map[string]string   `json:"metadata,omitempty"`
}

ReferenceMatch records how one parsed bibliography reference matched a source connector result.

type ReferenceNormalizationReport

type ReferenceNormalizationReport struct {
	PaperID        string                `json:"paperId"`
	ParserName     string                `json:"parserName,omitempty"`
	ParserVersion  string                `json:"parserVersion,omitempty"`
	Connector      string                `json:"connector"`
	References     int                   `json:"references"`
	Matched        int                   `json:"matched"`
	Ambiguous      int                   `json:"ambiguous"`
	Matches        []ReferenceMatch      `json:"matches"`
	AmbiguityQueue []ReferenceReviewItem `json:"ambiguityQueue,omitempty"`
}

ReferenceNormalizationReport summarizes connector normalization for parsed references.

func NormalizeParsedReferences

func NormalizeParsedReferences(ctx context.Context, connector sources.SourceConnector, doc ParsedDocument) (ReferenceNormalizationReport, error)

NormalizeParsedReferences queries a source connector for each parsed reference and records the top match.

type ReferenceReviewItem

type ReferenceReviewItem struct {
	Index      int     `json:"index"`
	Title      string  `json:"title,omitempty"`
	DOI        string  `json:"doi,omitempty"`
	Raw        string  `json:"raw,omitempty"`
	Confidence float64 `json:"confidence,omitempty"`
	Reason     string  `json:"reason"`
}

ReferenceReviewItem identifies a parsed reference that needs human review.

type ReferenceReviewReport

type ReferenceReviewReport struct {
	PaperID   string                `json:"paperId"`
	Threshold float64               `json:"threshold"`
	Items     []ReferenceReviewItem `json:"items"`
}

ReferenceReviewReport summarizes ambiguous parsed references for manual review.

func AmbiguousReferences

func AmbiguousReferences(doc ParsedDocument, threshold float64) ReferenceReviewReport

AmbiguousReferences flags references with missing identifiers/titles or low parser confidence.

type S2ORCJSONParser

type S2ORCJSONParser struct{ Version string }

S2ORCJSONParser adapts s2orc-doc2json-like JSON into ParsedDocument.

func (S2ORCJSONParser) Parse

func (p S2ORCJSONParser) Parse(ctx context.Context, data []byte, options ParseOptions) (ParsedDocument, error)

type Section

type Section struct {
	ID               string
	Title            string
	Offset           TextOffset
	ParserConfidence float64
	Passages         []Passage
}

Section is one parsed full-text section.

type TeXParser

type TeXParser struct{ Version string }

TeXParser extracts a lightweight ParsedDocument from arXiv TeX source.

func (TeXParser) Parse

func (p TeXParser) Parse(ctx context.Context, data []byte, options ParseOptions) (ParsedDocument, error)

type TextOffset

type TextOffset struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL