Skip to content

Commit

Permalink
feat: support for articles
Browse files Browse the repository at this point in the history
  • Loading branch information
Firgrep committed Nov 17, 2024
1 parent 44d12c2 commit 857453c
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 6 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
development_to_process.mdx
3 changes: 3 additions & 0 deletions TEST_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Running Integration Tests

- Remember to run `cargo test` instead of `cargo run test`!
63 changes: 61 additions & 2 deletions src/inserter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ fn generate_mdx_bibliography(entries: Vec<Entry>) -> String {
author[0].name, author[0].given_name
));
} else if author.len() == 2 {
// In Chicago style, when listing multiple authors in a bibliography entry,
// only the first author's name is inverted (i.e., "Last, First"). The second and subsequent
// authors' names are written in standard order (i.e., "First Last").
// This rule helps differentiate the primary author from co-authors.
mdx_html.push_str(&format!(
"{}, {} and {}, {}. ",
author[0].name, author[0].given_name, author[1].name, author[1].given_name
"{}, {} and {} {}. ",
author[0].name, author[0].given_name, author[1].given_name, author[1].name
));
} else {
mdx_html.push_str(&format!("{}, {}. ", author[0].name, author[0].given_name));
Expand All @@ -134,6 +138,61 @@ fn generate_mdx_bibliography(entries: Vec<Entry>) -> String {
}

mdx_html.push_str(&format!("{}: {}.", address, publisher));
}
EntryType::Article => {
let author = entry.author().unwrap();

let title_spanned: &[biblatex::Spanned<biblatex::Chunk>] = entry.title().unwrap();
let title = BiblatexUtils::extract_spanned_chunk(title_spanned);
let journal_spanned = entry.journal().unwrap();
let journal = BiblatexUtils::extract_spanned_chunk(&journal_spanned);

let volume_permissive = entry.volume().unwrap();
let volume = BiblatexUtils::extract_volume(&volume_permissive);

let number_spanned = entry.number().unwrap();
let number = BiblatexUtils::extract_spanned_chunk(&number_spanned);

let pages_permissive = entry.pages().unwrap();
let pages = BiblatexUtils::extract_pages(&pages_permissive);

let date = entry.date().unwrap();
let year = BiblatexUtils::extract_year(&date, entry.key.clone()).unwrap();
let translators = entry.translator().unwrap_or(Vec::new());

let doi = entry.doi().unwrap_or("".to_string());

// TODO refactor into a separate function
if author.len() > 2 {
mdx_html.push_str(&format!(
"{}, {} et al. ",
author[0].name, author[0].given_name
));
} else if author.len() == 2 {
// See comment above
mdx_html.push_str(&format!(
"{}, {} and {} {}. ",
author[0].name, author[0].given_name, author[1].given_name, author[1].name
));
} else {
mdx_html.push_str(&format!("{}, {}. ", author[0].name, author[0].given_name));
}
mdx_html.push_str(&format!("\"{}\". ", title));

let translators_mdx = generate_contributors(translators, "Translated".to_string());
if !translators_mdx.is_empty() {
mdx_html.push_str(&translators_mdx);
}

mdx_html.push_str(&format!(
"_{}_ {}, no. {} ({}): {}.",
journal, volume, number, year, pages
));
if !doi.is_empty() {
mdx_html.push_str(&format!(" https://doi.org/{}.", doi));
}


}
_ => println!("Entry type not supported: {:?}", entry.entry_type),
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
std::process::exit(1);
});

println!("===Prepyrus completed successfully!");
println!("✴️ Prepyrus completed successfully!");
}

/// Run all the methods of prepyrus
Expand Down
31 changes: 28 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use biblatex::{Bibliography, Chunk, Date, DateValue, Entry, PermissiveType, Spanned};
use serde::{Deserialize, Serialize};
use std::{
fs::{self, create_dir_all, File},
io::{self, Write},
path::Path,
fs::{self, create_dir_all, File}, io::{self, Write}, ops::Range, path::Path
};

pub struct BiblatexUtils;
Expand Down Expand Up @@ -38,6 +36,26 @@ impl BiblatexUtils {
}
}

pub fn extract_volume(volume: &PermissiveType<i64>) -> i64 {
match volume {
PermissiveType::Typed(volume) => *volume,
_ => 0,
}
}

pub fn extract_pages(pages: &PermissiveType<Vec<Range<u32>>>) -> String {
match pages {
PermissiveType::Typed(pages) => {
let mut pages_str = String::new();
for page in pages {
pages_str.push_str(&format!("{}–{}", page.start, page.end));
}
pages_str
}
_ => String::new(),
}
}

/// Use this to extract from a `Spanned<Chunk>` vector
///
/// ```rust
Expand Down Expand Up @@ -142,6 +160,13 @@ impl Utils {
args: &Vec<String>,
test_mode: Option<LoadOrCreateSettingsTestMode>,
) -> Result<Config, &'static str> {
println!("Number of arguments: {}", args.len());
println!("Arguments:");
for (i, arg) in args.iter().enumerate() {
println!(" args[{}]: {}", i, arg);
}


if args.len() < 4 {
return Err("Arguments missing: <bibliography.bib> <target_dir_or_file> <mode>");
}
Expand Down
33 changes: 33 additions & 0 deletions tests/integration_test_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,36 @@ fn run_verify_with_single_file() {
assert!(articles_file_data.len() == 1);
assert!(!articles_file_data.is_empty());
}

#[test]
fn run_process_with_single_file() {
let args = vec![
"program_index".to_string(),
"tests/mocks/test.bib".to_string(),
"tests/mocks/data/development_to_process.mdx".to_string(),
"process".to_string(),
];
let Config {
bib_file,
target_path,
mode,
settings,
} = Prepyrus::build_config(&args, Some(LoadOrCreateSettingsTestMode::Test)).unwrap_or_else(
|e| {
eprintln!("Error: {}", e);
std::process::exit(1);
},
);

let all_entries = Prepyrus::get_all_bib_entries(&bib_file).unwrap();
let mdx_paths = Prepyrus::get_mdx_paths(&target_path, Some(settings.ignore_paths)).unwrap();
let articles_file_data = Prepyrus::verify(mdx_paths, &all_entries).unwrap();

println!("{:?}", articles_file_data);
assert!(mode == "process");
assert!(articles_file_data.len() == 1);
assert!(!articles_file_data.is_empty());

Prepyrus::process(articles_file_data);
}

158 changes: 158 additions & 0 deletions tests/mocks/data/development_to_process.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
title: Development
description: Learn about the development of pure being from Hegel's Science of Logic.
isArticle: true
authors: Filip Niklas (2024)
editors:
contributors:
---

# MDX Test Sample: Broken Up For the Purposes of Testing Prepyrus

[Link to actual article](https://github.com/systemphil/sphil/blob/main/src/pages/hegel/reference/being/development.mdx)

### Quote

> _Being, pure being_ &ndash; without further determination. In its
> indeterminate immediacy it is equal only to itself and also not unequal with
> respect to another; it has no difference within it, nor any outwardly. If any
> determination or content were posited in it as distinct, or if it were posited
> by this determination or content as distinct from an other, it would thereby
> fail to hold fast to its purity. It is pure indeterminateness and emptiness.
> &ndash; There is _nothing_ to be intuited in it, if one can speak here of
> intuiting; or, it is only this pure empty intuiting itself. Just as little is
> anything to be thought in it, or, it is equally only this empty thinking.
> Being, the indeterminate immediate is in fact _nothing_, and neither more nor
> less than nothing (Hegel 2010, 59/21.68-9).
### Examination

```md
In its indeterminate immediacy it is equal only to itself and also not unequal
with respect to another; it has no difference within it, nor any outwardly.
```

Lastly, Hegel equates the activity of intuiting pure being with the matter
itself. In intuiting that pure being is nothing&mdash;or there is nothing to be
intuited in pure being&mdash;the intuiting activity is itself neither more or
less than the matter it intuits, namely, pure emptiness.

[^1]: [Spinoza on Intuition from the Stanford Encyclopedia of Philosophy](https://plato.stanford.edu/entries/spinoza-epistemology-mind/#KindCognIIIIntu)

```md
Just as little is anything to be thought in it, or, it is equally only this
empty thinking. Being, the indeterminate immediate is in fact _nothing_, and
neither more nor less than nothing
```

Burbidge stresses the intellectual dimension of thought and the operations that
the understanding undergoes in preparing for pure thinking. Pure thought is
defined as the sphere of intellectual relations purged of spatio-temporal,
subjective and cultural contingencies (Burbidge 1981, 37). As a _science_, the
logic articulates the relations between these intellectual relations: "in
rendering a concept precise, thought moves to a related category; this movement
in turn is named, and itself becomes a new concept" (Burbidge 1981, 37). In
other words, pure thought is the purified intellectual dimension that considers
intellectual relations _as_ intellectual relations and discovers what particular
inter-intellectual relations obtain or simply pure concepts (James 2024).

Moreover, further to this, if the science of logic is to become _a system_, it
must consider its starting point carefully, since a paradoxical problem presents
itself at the outset. Logic cannot itself begin as the product of a process,
since that inevitably entails that that process is then the actual starting
point. "This poses a paradoxical problem," Burbidge notes, "The promotive
concept is to be immediate and not the determinate result of inferential
transitions. Yet is it is the name of an intellectual relation, presupposing
terms to be related" (Burbidge 1981, 37).

Any intellectual relation condition by distinctive moments of personal or social
history must be left aside in the abstract discipline of thought. "Yet once the
relativizing conditions have been dissolved away in pure self-knowledge, we are
left with simple intellectual relations that are not in themselves determinate"
(Burbidge 1981, 38). This simple intellectual relating bereft of all reference
terms is prior to even the reference immediacy, as that is a reflective thought
that introduces a contrast with mediation. Instead, it simply _is_.

> In other words the verb 'to be' fills the requirement quite precisely: as a
> verb it expresses a relating; it can be used with any subject whatsoever; and
> it is incomplete and points toward the need for further
> determination&mdash;although not itself determined it is open to
> determinations ... _Being_ is thus the most primitive category of the logical
> science. It lacks any determinations by which thought can distinguish one
> thing or idea from another. But at the same time it articulates a
> comprehensive relation that is immediately common to all things or ideas
> (Burbidge 1981, 38).
### Houlgate

Stephen Houlgate emphasizes that the start of Hegel's _Logic_ is both a logic
and a metaphysics at once. He further points out that the thought of `being`
under consideration is not the being _of something_ or the being expressed in
the _copula_ of a judgment (e.g. the squirrel _is_ fluffy), "Being is to be
understood simply as pure indeterminate being" (Houlgate 2022, 135).

> This is precisely what makes being “changeless”: for, as not-nothing, being
> neither arises from, nor passes into, nothing. In Parmenides' words, “it
> exists without beginning or ceasing”, but, “remaining the same and in the same
> place, it lies on its own and thus fixed it will remain”. Parmenides goes on
> to claim that “strong necessity holds it [being] within the bonds of a limit”
> &ndash; a limit that preserves being as being and keeps it apart from nothing
> (Houlgate 2022, 136).
Moreover, Houlgate points out that `being` is not to be understood in terms of
the negation of immediacy ("im-mediacy") or the negation of determinacy
("in-determinate"). This line of thinking would also render `being` something
determinate and fail to hold fast to its purity. Instead, `being` must be
understood _in_ its immediacy and indeterminate, rather than _as_ immediate and
indeterminate. "At the start of logic being must be thought in its utter
indeterminacy and immediacy &ndash; and so without being explicitly contrasted
with determinacy or mediation &ndash; as pure and simple being" (Houlgate 2022,
136).

This thinking in terms of _in_ rather than _as_ further helps understand how
Hegel's initial fragment concerning `without further determination` is not a
defining of `being` _as_ the-being-without-determination, but that of holding
`being` _free_ of determination, and to think it in its purity and simplicity
(Houlgate 2022, 136).

It seen how a non-trivial amount of effort is needed to keep at bay the mind's
reflective reflexes, which employ difference, equality, likeness and so forth in
understanding a matter. This language of difference with its reflective
categories cannot be entirely avoided, but they need not determine the matter,
that is, understand `being` in terms of contrasts and mediation. Using negation
on these reflective categories, or just careful language, one is able to keep at
bay their determination of the matter at hand and allow it to be understood
freely on its own terms, which in the case of `being` means its simplicity and
purity (Houlgate 2022, 137).

> To think of being in this way, we must first abstract from all we ordinarily
> take being to be; but we must then abstract from, and set aside, the very fact
> that pure being is the result of abstraction. Only thus will the process of
> abstraction lead to the thought of being as pure and immediate, rather than as
> mediated result (or “essence”)(Houlgate 2022, 138).
### McTaggart

John McTaggart looks at Hegel's opening category not so much an affirmation of
being as an affirmation of nothing else. He further considers that being has no
nature, since any nature would indicate some kind of determinacy vis-à-vis
another being whose nature is different; however, with pure being this cannot be
case. "Any determination would give it some particular nature, as against some
other particular nature&mdash;would make it _X_ rather than _not-X_. It has
therefore no determination whatever" (McTaggart 1910, 15).


## Bibliography

<div className="text-sm">
- Hegel, G.W.F. 2010. _Georg Wilhelm Friedrich Hegel: The Science of Logic_. Translated by George Di Giovanni. Cambridge: Cambridge University Press.
- Burbidge, J.W. 1981. _On Hegel's Logic: Fragments of a Commentary_. Atlantic Highlands, N.J.: Humanities Press.
- James, Daniel and Franz Knappik. "Introduction to Part 2 of the Themed Issue, ‘Racism and Colonialism in Hegel’s Philosophy’: Common Objections and Questions for Future Research". Translated by Paul Guyer, and Allen W. Wood. _Hegel Bulletin_ 45, no. 2 (2024): 181–184. https://doi.org/10.1017/hgl.2024.38.
- Houlgate, S. 2022. _Hegel on Being_. London: Bloomsbury Academic.
- McTaggart, J.M.E. 1910. _A Commentary on Hegel's Logic_. Cambridge: Cambridge University Press.
</div>

**Authors**
Filip Niklas (2024)

**Notes**
12 changes: 12 additions & 0 deletions tests/mocks/test.bib
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,16 @@ @book{mctaggart1910hegel
year = {1910},
publisher = {Cambridge University Press},
address = {Cambridge}
}

@article{James_Knappik_2024,
title={Introduction to Part 2 of the Themed Issue, ‘Racism and Colonialism in Hegel’s Philosophy’: Common Objections and Questions for Future Research},
volume={45},
DOI={10.1017/hgl.2024.38},
number={2},
journal={Hegel Bulletin},
author={James, Daniel and Knappik, Franz},
translator = {Guyer, Paul and Wood, Allen W.},
year={2024},
pages={181–184}
}

0 comments on commit 857453c

Please sign in to comment.