evidence-citations 0.9.0.post4__py3-none-any.whl

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.

Potentially problematic release.


This version of evidence-citations might be problematic. Click here for more details.

Files changed (59) hide show
  1. evidence_citations/__init__.py +27 -0
  2. evidence_citations/_academic.py +57 -0
  3. evidence_citations/_candidate_filter.py +54 -0
  4. evidence_citations/_column_model.py +850 -0
  5. evidence_citations/_column_ticks.py +637 -0
  6. evidence_citations/_context.py +212 -0
  7. evidence_citations/_control.py +40 -0
  8. evidence_citations/_controlled.py +184 -0
  9. evidence_citations/_dot_leaders.py +205 -0
  10. evidence_citations/_field_labels.py +59 -0
  11. evidence_citations/_field_prose.py +158 -0
  12. evidence_citations/_graph.py +518 -0
  13. evidence_citations/_job_cache.py +38 -0
  14. evidence_citations/_legacy.py +1625 -0
  15. evidence_citations/_linguistics.py +97 -0
  16. evidence_citations/_markdown.py +53 -0
  17. evidence_citations/_money.py +84 -0
  18. evidence_citations/_multilingual.py +305 -0
  19. evidence_citations/_negation.py +12 -0
  20. evidence_citations/_page_cache.py +76 -0
  21. evidence_citations/_partial_recovery.py +117 -0
  22. evidence_citations/_pdf_text.py +180 -0
  23. evidence_citations/_pdf_worker.py +68 -0
  24. evidence_citations/_physical_relations.py +1089 -0
  25. evidence_citations/_prepared.py +69 -0
  26. evidence_citations/_quoted_recovery.py +173 -0
  27. evidence_citations/_recovery.py +427 -0
  28. evidence_citations/_reuse.py +118 -0
  29. evidence_citations/_row_projection.py +2709 -0
  30. evidence_citations/_runtime.py +22 -0
  31. evidence_citations/_separator_paths.py +73 -0
  32. evidence_citations/_streaming.py +191 -0
  33. evidence_citations/_table_assignment.py +144 -0
  34. evidence_citations/_table_headers.py +108 -0
  35. evidence_citations/_table_hypotheses.py +233 -0
  36. evidence_citations/_table_inference.py +194 -0
  37. evidence_citations/_table_layout.py +164 -0
  38. evidence_citations/_table_pixels.py +273 -0
  39. evidence_citations/_tables.py +77 -0
  40. evidence_citations/_temporal.py +29 -0
  41. evidence_citations/_year_table.py +395 -0
  42. evidence_citations/answer.py +718 -0
  43. evidence_citations/claims.py +289 -0
  44. evidence_citations/compat.py +36 -0
  45. evidence_citations/engine.py +765 -0
  46. evidence_citations/errors.py +38 -0
  47. evidence_citations/executor.py +43 -0
  48. evidence_citations/integration.py +78 -0
  49. evidence_citations/limits.py +9 -0
  50. evidence_citations/models.py +171 -0
  51. evidence_citations/planning.py +192 -0
  52. evidence_citations/protocol.py +129 -0
  53. evidence_citations-0.9.0.post4.dist-info/METADATA +185 -0
  54. evidence_citations-0.9.0.post4.dist-info/RECORD +59 -0
  55. evidence_citations-0.9.0.post4.dist-info/WHEEL +5 -0
  56. evidence_citations-0.9.0.post4.dist-info/licenses/COMPONENTS.txt +29 -0
  57. evidence_citations-0.9.0.post4.dist-info/licenses/LICENSE +661 -0
  58. evidence_citations-0.9.0.post4.dist-info/licenses/rights/AGPL-3.0-only.txt +661 -0
  59. evidence_citations-0.9.0.post4.dist-info/top_level.txt +1 -0
@@ -0,0 +1,27 @@
1
+ """Reusable citation verification. Importing the package performs no I/O."""
2
+ from .claims import (AtomicClaim, ClaimGroup, EvidenceLink, EvidenceScope, FactValue,
3
+ SourceFact, TableRelation, TableEvidence, TableCell, TableLayout, ClaimDecision, GroupDecision, ClaimVerificationResult)
4
+ from .planning import ClaimPlan, ClaimAnnotation, prepare_claims
5
+ from .executor import SharedPDFExecutor
6
+ from .engine import CitationEngine
7
+ from .errors import CitationError, InvalidInput, MissingPDFDependency, VerificationCancelled, VerificationTimeout, CapacityExceeded
8
+ from .models import AuditEntry, CitationRecord, CoverageUnit, Document, DocumentFingerprint, Segment, Source, VerificationResult
9
+ from .answer import AnswerVerificationResult
10
+ from ._streaming import IncrementalStreamCleaner, TextPatch
11
+ from .protocol import StreamCleaner, clean_answer, generation_instructions, parse_records
12
+
13
+ __version__ = "0.9.0"
14
+ __all__ = [
15
+ "AnswerVerificationResult",
16
+ "IncrementalStreamCleaner", "TextPatch",
17
+ "SharedPDFExecutor",
18
+ "ClaimPlan", "ClaimAnnotation", "prepare_claims",
19
+ "AtomicClaim", "ClaimGroup", "EvidenceLink", "EvidenceScope", "FactValue",
20
+ "TableCell", "TableLayout",
21
+ "SourceFact", "TableRelation", "TableEvidence", "ClaimDecision", "GroupDecision", "ClaimVerificationResult",
22
+ "CitationEngine", "CitationRecord", "Source", "Segment", "Document", "DocumentFingerprint",
23
+ "VerificationResult", "CoverageUnit", "AuditEntry", "StreamCleaner",
24
+ "clean_answer", "generation_instructions", "parse_records", "CitationError",
25
+ "VerificationTimeout", "CapacityExceeded",
26
+ "InvalidInput", "MissingPDFDependency", "VerificationCancelled",
27
+ ]
@@ -0,0 +1,57 @@
1
+ """Recognize explicitly labelled, consecutive academic years, not amounts/IDs."""
2
+ import re
3
+
4
+
5
+ _YEAR_LABEL = r'(?:akademik\s+yil(?:i)?|egitim(?:[\s\-–—‐‑]+ogretim)?\s+yili|academic\s+(?:year|session)|annee\s+(?:universitaire|academique|scolaire)|periode\s+universitaire(?:\s*/\s*year)?)'
6
+
7
+
8
+ def academic_year_value(text, fold):
9
+ """A complete year value with optional labels, never arbitrary qualifiers."""
10
+ value = fold(text).strip().rstrip('.!?').strip()
11
+ value = re.sub(r'\b((?:akademik|egitim(?:[\s\-–—‐‑]+ogretim)?)\s+yili)dir$', r'\1', value)
12
+ pattern = (r'(?:' + _YEAR_LABEL + r'\s+)?(19\d{2}|20\d{2}|21\d{2})'
13
+ r'\s*[-–—/]\s*(19\d{2}|20\d{2}|21\d{2})(?:\s+' + _YEAR_LABEL + r')?')
14
+ match = re.fullmatch(pattern, value)
15
+ if match is None or int(match[2]) != int(match[1]) + 1:
16
+ return None
17
+ return match[1], match[2]
18
+
19
+
20
+ def compact_field_row(text, normalize):
21
+ """Split a small allowlist of complete labels without altering raw offsets."""
22
+ labels = {
23
+ 'annee universitaire', 'annee academique', 'annee scolaire',
24
+ 'periode universitaire', 'periode universitaire year',
25
+ 'academic year', 'academic session', 'akademik yil', 'akademik yili',
26
+ 'egitim yili', 'egitim ogretim yili', 'kayit donemi', 'kayit yili',
27
+ 'formation', 'programme', 'program', 'field of study',
28
+ 'domaine d etudes', 'kayitli alan', 'kayitli bolum', 'kayitli program',
29
+ 'ogrenim alani', 'egitim alani',
30
+ }
31
+ words = list(re.finditer(r'\S+', text))
32
+ for word in reversed(words[:5]):
33
+ label, value = text[:word.end()], text[word.end():].strip()
34
+ if value and normalize(label) in labels:
35
+ return label, value
36
+ return None
37
+
38
+
39
+ def academic_year_facts(text, fold):
40
+ pattern = r'(?<![\w/])(19\d{2}|20\d{2}|21\d{2})\s*[-–—/]\s*(19\d{2}|20\d{2}|21\d{2})(?![\w/])'
41
+ prefix = r'\b(?:' + _YEAR_LABEL + r'|kayit\s+(?:donemi|yili)|registration\s+(?:year|period))\s*[:\-]?\s*$'
42
+ suffix = r'^\s*(?:(?:akademik|egitim(?:[\s\-–—‐‑]+ogretim)?)\s+)?(?:yil(?:i|inda|inin|ina)?|academic\s+year)\b'
43
+ facts = []
44
+ for match in re.finditer(pattern, text):
45
+ first, second = map(int, match.groups())
46
+ if second != first + 1:
47
+ continue
48
+ before = fold(text[max(0, match.start()-80):match.start()])
49
+ after = fold(text[match.end():match.end()+60])
50
+ semester = re.search(r'^\s*(?:guz|bahar)(?:\s+(?:donemi|yariyili|yariyilinda))?\b|^\s*(?:fall|spring)\s+(?:semester|term)\b', after)
51
+ enrollment = re.search(r'\b(?:enrolled for the year|inscrit pour la periode universitaire)\s*$', before)
52
+ exchange = re.search(r'\b(?:exchange student|etudiant en echange)\s*$', before)
53
+ if not (re.search(prefix, before) or re.search(suffix, after) or semester or exchange or enrollment):
54
+ continue
55
+ facts.append(dict(value=f'{first}/{second}', unit='academic_year', role='academic_year',
56
+ entity=None, qualifier='exact', period=None, start=match.start(), end=match.end()))
57
+ return facts
@@ -0,0 +1,54 @@
1
+ """Cheap, conservative screening shared by live preparation and final fallback."""
2
+ import re
3
+ from ._field_prose import field_claim
4
+
5
+
6
+ def _parts(core, unit):
7
+ """Conservative clause proposals, never free-form semantic atomization."""
8
+ parts = [p.strip() for p in re.split(r';|(?<!\d),(?!\d)|\b(?:ve|and|et|olup)\b', unit)]
9
+ typed = lambda p: bool(core['citation_fields'](p) or core['citation_date_values'](p)
10
+ or core['citation_quantity_facts'](p))
11
+ return parts if len(parts) > 1 and sum(typed(p) for p in parts) > 1 else [unit]
12
+
13
+
14
+ def queries(core, unit, prepared=None):
15
+ # A supported period adjunct is not an independent numeric claim. Keep
16
+ # fully parsed statements intact for money/year/compound fallback.
17
+ parts = [unit] if statement_key(unit, prepared) is not None else _parts(core, unit)
18
+ clause = field_claim(unit, allow_prefix=True)
19
+ if clause and clause['start']:
20
+ parts = list(dict.fromkeys([clause['span'], *parts]))
21
+ for part in parts:
22
+ needle = core['citation_surface_index'](part)[0]
23
+ clause = field_claim(part)
24
+ fields = ({clause['kind']} if clause else core['citation_fields'](part.split(':', 1)[0]) if ':' in part else set())
25
+ yield part, needle, fields
26
+
27
+
28
+ def candidate_view(core, prepared, candidate):
29
+ text = candidate['text']
30
+ return (core['citation_cached'](prepared, ('fallback_surface', text),
31
+ lambda: core['citation_surface_index'](text)[0]),
32
+ core['citation_cached'](prepared, ('fallback_fields', text),
33
+ lambda: core['citation_fields'](text)))
34
+
35
+
36
+ _UNPARSED = object()
37
+
38
+
39
+ def statement_key(text, prepared=None):
40
+ from ._controlled import parse_statement
41
+ from ._legacy import citation_cached
42
+ return citation_cached(prepared, ('controlled-statement', text), lambda: parse_statement(text))
43
+
44
+
45
+ def may_support(needle, fields, surface, source_fields, *, prepared=None, statement=_UNPARSED):
46
+ if (needle and needle in surface) or (fields and fields.issubset(source_fields)):
47
+ return True
48
+ # Parse a claim once before enumerating its candidate pool. None is a
49
+ # cached abstention, distinct from a caller that has not parsed it yet.
50
+ if statement is _UNPARSED:
51
+ statement = statement_key(needle, prepared)
52
+ if statement is None:
53
+ return False
54
+ return statement == statement_key(surface, prepared)