Citation sources
Reading the source a citation check quotes, and deciding whether it is tied to the reference.
judge_citation reads the source itself: it never takes text the agent pastes. What it read is kept
as an observation, a JSON record logged with the call: which file or URL, the digest of the bytes,
the digest of their normalised text, where the quoted passage is in that text, and what ties the source
to the reference. The bytes themselves are not logged. The decision the check rests on (tie) is made
from the observation, the reference's bibliography entry and the digests start_run pinned, so the run
can be rebuilt from its log without reading anything again; replay reads the bytes again
(verify_observation) and refuses an observation they do not give.
A source is tied to the reference when it is one of:
- the file named by the entry's key in the run's copy of the cited works,
cited/, while its bytes still have the digeststart_runrecorded; - the arXiv paper the entry names, fetched by the tool from the identifier in the entry (never the agent's), at the version the entry names or, when it names none, the current one, whose version is recorded;
- the work the entry's DOI resolves to: the agent's URL, after redirects, ends at the URL the tool
reached by requesting
https://doi.org/<the entry's DOI>, or the agent gave that DOI URL itself.
Any other source is read, and its passage located, but its check is an error: it moves no credence.
SourceError
¶
Bases: Exception
The source cannot be read.
Attributes:
| Name | Type | Description |
|---|---|---|
code |
|
Source code in src/credencegraph_extract/citation.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
__init__(code, message)
¶
Make the error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
|
required |
message
|
str
|
Why, in words. |
required |
Source code in src/credencegraph_extract/citation.py
76 77 78 79 80 81 82 83 84 | |
arxiv_id(reference)
¶
Return the arXiv identifier a bibliography entry names, if it names one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Node
|
The reference node. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The first identifier in its statement, or |
Source code in src/credencegraph_extract/citation.py
87 88 89 90 91 92 93 94 95 96 97 | |
entry_doi(reference)
¶
Return the DOI a bibliography entry names, in lower case, if it names one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Node
|
The reference node. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The first DOI in its statement, without trailing punctuation, or |
Source code in src/credencegraph_extract/citation.py
100 101 102 103 104 105 106 107 108 109 110 | |
key_file(reference, names)
¶
Return the file of the cited works that a reference's key names: the first of its suffixes there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Node
|
The reference node. |
required |
names
|
Mapping[str, str] | set[str]
|
The names of the files of the run's cited works. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
|
Source code in src/credencegraph_extract/citation.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
read_cited(run_dir, source, passage)
¶
Read a file of the run's copy of the cited works.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_dir
|
Path
|
The run directory. |
required |
source
|
str
|
The file's name, or a path to it in |
required |
passage
|
str
|
The passage the agent quotes. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], bytes]
|
The observation ( |
Raises:
| Type | Description |
|---|---|
SourceError
|
If the path is not a regular file directly in the run's |
Source code in src/credencegraph_extract/citation.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
read_url(reference, source, passage, fetcher=fetch)
¶
Fetch a URL source, and what ties it to the reference.
An arXiv URL of the identifier the entry names is read from arXiv at the entry's version, or the current one; a doi.org URL of the entry's DOI is read through doi.org. Any other URL is read as given, and, when the entry names a DOI, the DOI is resolved too, so the two final URLs can be compared.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Node
|
The reference node. |
required |
source
|
str
|
The URL the agent gave. |
required |
passage
|
str
|
The passage the agent quotes. |
required |
fetcher
|
Fetch
|
Fetches a URL under the fetch policy. |
fetch
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The observation ( |
bytes
|
|
Raises:
| Type | Description |
|---|---|
SourceError
|
If a URL is refused, cannot be fetched, or the body cannot be read. |
Source code in src/credencegraph_extract/citation.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
text_of(data, kind)
¶
Return the normalised text of a source's bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The bytes. |
required |
kind
|
str
|
A file suffix ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text, normalised as a quoted passage is. |
Raises:
| Type | Description |
|---|---|
SourceError
|
If the kind is not one of those, or the bytes cannot be read as it. |
Source code in src/credencegraph_extract/citation.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
tie(reference, pins, observation)
¶
Decide whether an observed source is tied to the reference; return why not, or None when it is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Node
|
The reference node. |
required |
pins
|
Mapping[str, str]
|
The digest of each file of the cited works, as |
required |
observation
|
Mapping[str, Any]
|
What the tool read. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
|
Source code in src/credencegraph_extract/citation.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
verify_observation(observation, data, passage)
¶
Return the fields of an observation that the source's bytes do not give again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation
|
Mapping[str, Any]
|
What the tool recorded. |
required |
data
|
bytes
|
The bytes, found by their digest. |
required |
passage
|
str
|
The passage the agent quoted. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The names of the fields that differ: |
Source code in src/credencegraph_extract/citation.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |