Skip to content

Commit

Permalink
chore: renamed to forn
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed May 8, 2023
1 parent 4106d7b commit eaa2149
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 89 deletions.
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "california"
name = "forn"
version = "0.1.0"
edition = "2021"

Expand All @@ -12,7 +12,7 @@ serde_json = "1"
anyhow = "1"
rand = "0.8"
lazy_static = "1"
rhai = { version = "1.14.0", features = ["serde", "sync", "internals"] }
rhai = { version = "1.14.0", features = ["serde", "sync"] }
include_dir = "0.7.3"
uuid = { version = "1.3.2", features = ["v4", "serde"] }

Expand All @@ -23,11 +23,11 @@ whoami = { version = "1.4.0", optional = true }
termion = { version = "2.0.1", optional = true }

[lib]
name = "california"
name = "forn"
path = "src/lib.rs"

[[bin]]
name = "california"
name = "forn"
path = "src/bin/main.rs"

[features]
Expand Down
62 changes: 31 additions & 31 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions common_adapters/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Common California Adapters
# Common Forn Adapters

This directory contains a number of common example adapters that have been contributed by the community to help first-time California users get on their feet with creating a set for the first time. The reason California does not by default provide any inbuilt adapters, as it does with learning methods, is because it's much more common for people to work with their own custom note formats. For example, a common use-case is to have a series of question/answer formatted notes exported in Markdown from some other app, and the format each person uses will be slightly different, hence why we don't prescribe anything.
This directory contains a number of common example adapters that have been contributed by the community to help first-time Forn users get on their feet with creating a set for the first time. The reason Forn does not by default provide any inbuilt adapters, as it does with learning methods, is because it's much more common for people to work with their own custom note formats. For example, a common use-case is to have a series of question/answer formatted notes exported in Markdown from some other app, and the format each person uses will be slightly different, hence why we don't prescribe anything.

You can easily create your own adapter scripts in [Rhai], a simple scripting language, by modifying the scripts in here, or by writing your own from scratch. If you need any help, don't hesitate to create a [new discussion]!
2 changes: 1 addition & 1 deletion src/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use uuid::Uuid;

impl Set {
/// Creates a new [`Set`] from the given source using the given Rhai script. The script is required
/// to assemble a Rhai array of question/answer tuples, and California will do the rest of the work
/// to assemble a Rhai array of question/answer tuples, and Forn will do the rest of the work
/// to create a full set instance.
///
/// **IMPORTANT:** The engine provided to this function must have the necessary functions registered for
Expand Down
32 changes: 16 additions & 16 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ compile_error!("the cli binary must be built with the `cli` feature flag");
#[cfg(feature = "cli")]
fn main() -> anyhow::Result<()> {
use anyhow::Context;
use california::{California, Set};
use forn::{Forn, Set};
use clap::Parser;
use opts::{Args, Command};
use std::fs;
Expand All @@ -25,8 +25,8 @@ fn main() -> anyhow::Result<()> {
fs::read_to_string(adapter).with_context(|| "failed to read adapter script")?;
let method = method_from_string(method)?;

let california = California::new_set(contents, &adapter_script, method)?;
let json = california.save_set()?;
let forn = Forn::new_set(contents, &adapter_script, method)?;
let json = forn.save_set()?;
fs::write(output, json).with_context(|| "failed to write new set to output file")?;

println!("New set created!");
Expand All @@ -41,14 +41,14 @@ fn main() -> anyhow::Result<()> {
let json =
fs::read_to_string(&set_file).with_context(|| "failed to read from set file")?;
let set = Set::from_json(&json)?;
let mut california = California::from_set(set);
let mut forn = Forn::from_set(set);
let method = method_from_string(method)?;
if reset && confirm("Are you absolutely certain you want to reset your learn progress? This action is IRREVERSIBLE!!!")? {
california.reset_learn(method.clone())?;
forn.reset_learn(method.clone())?;
} else {
println!("Continuing with previous progress...");
}
let mut driver = california.learn(method)?;
let mut driver = forn.learn(method)?;
driver.set_target(ty);
if let Some(count) = count {
driver.set_max_count(count);
Expand All @@ -72,13 +72,13 @@ fn main() -> anyhow::Result<()> {
let json =
fs::read_to_string(&set_file).with_context(|| "failed to read from set file")?;
let set = Set::from_json(&json)?;
let mut california = California::from_set(set);
let mut forn = Forn::from_set(set);
if reset && confirm("Are you sure you want to reset your test progress?")? {
california.reset_test();
forn.reset_test();
} else {
println!("Continuing with previous progress...");
}
let mut driver = california.test();
let mut driver = forn.test();
driver.set_target(ty);
if let Some(count) = count {
driver.set_max_count(count);
Expand Down Expand Up @@ -134,9 +134,9 @@ fn main() -> anyhow::Result<()> {
///
/// For custom scripts, this will make their name be the filename of the script with the current user's username prefixed.
#[cfg(feature = "cli")]
fn method_from_string(method_str: String) -> anyhow::Result<california::RawMethod> {
fn method_from_string(method_str: String) -> anyhow::Result<forn::RawMethod> {
use anyhow::bail;
use california::RawMethod;
use forn::RawMethod;
use std::{fs, path::PathBuf};

if RawMethod::is_inbuilt(&method_str) {
Expand All @@ -145,7 +145,7 @@ fn method_from_string(method_str: String) -> anyhow::Result<california::RawMetho
// It's a path to a custom script
let method_path = PathBuf::from(&method_str);
if let Ok(contents) = fs::read_to_string(&method_path) {
// Follow California's recommended naming conventions for custom methods
// Follow Forn's recommended naming conventions for custom methods
let name = format!(
"{}/{}",
whoami::username(),
Expand All @@ -156,7 +156,7 @@ fn method_from_string(method_str: String) -> anyhow::Result<california::RawMetho
body: contents,
})
} else {
bail!("provided method is not inbuilt and does not represent a valid method file (or if it did, california couldn't read it)")
bail!("provided method is not inbuilt and does not represent a valid method file (or if it did, forn couldn't read it)")
}
}
}
Expand All @@ -166,7 +166,7 @@ fn method_from_string(method_str: String) -> anyhow::Result<california::RawMetho
///
/// This returns the number of cards reviewed.
#[cfg(feature = "cli")]
fn drive<'a>(mut driver: california::Driver<'a, 'a>, set_file: &str) -> anyhow::Result<u32> {
fn drive<'a>(mut driver: forn::Driver<'a, 'a>, set_file: &str) -> anyhow::Result<u32> {
use anyhow::{bail, Context};
use std::{
fs,
Expand Down Expand Up @@ -277,10 +277,10 @@ fn confirm(message: &str) -> anyhow::Result<bool> {
mod opts {
use std::path::PathBuf;

use california::CardType;
use forn::CardType;
use clap::{Parser, Subcommand};

/// California: a spaced repetition CLI to help you learn stuff
/// Forn: a spaced repetition CLI to help you learn stuff
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
Expand Down
2 changes: 1 addition & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'e, 's> Driver<'e, 's> {
}
}
/// Gets the first question/answer pair of this run. While it is perfectly safe to run this at any time, it
/// is semantically nonsensical to run this more than once, as California's internals will become completely
/// is semantically nonsensical to run this more than once, as Forn's internals will become completely
/// useless. If you want to display each card to the user only once, irrespective of the metadata attached to
/// it, you should instantiate the driver for a test, rather than a learning session.
///
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ use anyhow::Result;
use fancy_regex::Regex;
use rhai::{Dynamic, Engine, EvalAltResult};

/// A California engine, which can act as the backend for learn operations. An instance of this `struct` should be
/// A Forn engine, which can act as the backend for learn operations. An instance of this `struct` should be
/// instantiated with a [`Set`] to operate on and an operation to perform.
///
/// The engine has the same lifetime as the reference it is given to its interface for communicating with the host
/// environment.
pub struct California {
pub struct Forn {
/// The set being operated on.
set: Set,
/// A Rhai scripting engine used to compile and execute the scripts that drive adapters and learning methods.
rhai_engine: Engine,
}
impl California {
impl Forn {
/// Creates a new set from the given source file text and adapter script. This is a thin wrapper over the `Set::new_with_adapter`
/// method, abstracting away the internal use of a Rhai engine. In general, you should prefer this method, as there is no additional
/// overhead to using it.
Expand All @@ -36,7 +36,7 @@ impl California {
rhai_engine: engine,
})
}
/// Creates a new California engine. While not inherently expensive, this should generally only be called once, or when
/// Creates a new Forn engine. While not inherently expensive, this should generally only be called once, or when
/// the system needs to restart.
pub fn from_set(set: Set) -> Self {
Self {
Expand Down Expand Up @@ -82,7 +82,7 @@ impl California {
self.set.reset_test();
}

/// Creates a Rhai engine with the utilities California provides all pre-registered.
/// Creates a Rhai engine with the utilities Forn provides all pre-registered.
fn create_engine() -> Engine {
let mut engine = Engine::new();
// Regex utilities (with support for backreferences etc.)
Expand Down
2 changes: 1 addition & 1 deletion src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl Set {
/// Lists all the terms in the set of the given type, returning them as pairs of questions and answers.
///
/// *Note: it is deliberately impossible to return card metadata through the traditional interface, and one should
/// independently process that if this is required. The generical philosophy of California is not to interact with
/// independently process that if this is required. The generical philosophy of Forn is not to interact with
/// the method-specific metadata whenever possible, however.*
pub fn list(&self, ty: CardType) -> Vec<SlimCard> {
self.cards
Expand Down
8 changes: 4 additions & 4 deletions src/methods/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# California Learning Methods
# Forn Learning Methods

This diretory defines all the learning methods in California. Because this is a tool designed to have many more learning methods implemented rapidly in the future, and to make that as easy as possible, both for Git merge conflicts and for developers writing new methods, we allow all methods to be written in Rhai, a very capable and extensible scripting language for Rust.
This diretory defines all the learning methods in Forn. Because this is a tool designed to have many more learning methods implemented rapidly in the future, and to make that as easy as possible, both for Git merge conflicts and for developers writing new methods, we allow all methods to be written in Rhai, a very capable and extensible scripting language for Rust.

Each method script defines a few things: a constant called `RESPONSES`, which should be a list of all the responses a user can choose from after they've seen the answer to a question (e.g. `y/n`, `1/2/3/4/5`, `great/good/bad`); a function called `get_weight` that takes in the *method state* for the current term and produces a weighting for it; and an `adjust_card` function that takes in the user's response (which will be one of the elements in `RESPONSES`) and adjusts the method state for that particular card. Note that the filename of the script will be used as its method name, which can be specified on the command line (e.g. `--method <name>`). This does not include the `.rhai` extension.

Essentially, California operates by having methods store some arbitrary state for each term in a set, which is then stored in the set file, and the method script is later used to determine the weightings of each term in the set. **The weight of a term determines how likely it is to be presented to the user when the system next needs to choose a term to present.** In general, method state should be kept as lightweight as possible to minimise the burden of storing a method state for every single term for large files (which may incur both storage and I/O penalties for the user).
Essentially, Forn operates by having methods store some arbitrary state for each term in a set, which is then stored in the set file, and the method script is later used to determine the weightings of each term in the set. **The weight of a term determines how likely it is to be presented to the user when the system next needs to choose a term to present.** In general, method state should be kept as lightweight as possible to minimise the burden of storing a method state for every single term for large files (which may incur both storage and I/O penalties for the user).

This project has a general policy of accepting all new methods that are useful, as we want to give people a large choice of what method they use for their own personal learning. Some methods will be intended for cramming, others for longer-term learning, etc. It should be completely possible to implement the full gamut of scientific research on spaced repetition and learning methods through California, all in Rhai! If you would like to submit a new method, please open a [pull request](https://github.com/arctic-hen7/california/pulls) and tell us about it! If you'd like to try out a new method, you can write the Rhai script for it and pass that file to California as a method, and it will happily run it, letting you tweak your method to find the best implementation.
This project has a general policy of accepting all new methods that are useful, as we want to give people a large choice of what method they use for their own personal learning. Some methods will be intended for cramming, others for longer-term learning, etc. It should be completely possible to implement the full gamut of scientific research on spaced repetition and learning methods through Forn, all in Rhai! If you would like to submit a new method, please open a [pull request](https://github.com/arctic-hen7/forn/pulls) and tell us about it! If you'd like to try out a new method, you can write the Rhai script for it and pass that file to Forn as a method, and it will happily run it, letting you tweak your method to find the best implementation.
10 changes: 5 additions & 5 deletions src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ impl<'e> Method<'e> {
/// # Panics
///
/// This will panic if compilation fails, as compilation should never fail for an inbuilt method, and this would represent
/// a bug in California.
/// a bug in Forn.
fn from_inbuilt(method_name: &str, engine: &'e Engine) -> Result<Self> {
if !Method::is_inbuilt(method_name) {
bail!("provided method name '{method_name}' is not an inbuilt method (are you using the latest version of california?)");
bail!("provided method name '{method_name}' is not an inbuilt method (are you using the latest version of forn?)");
}
let script = METHODS
.get_file(method_name.to_string() + ".rhai")
.unwrap()
.contents_utf8()
.expect("inbuilt method should be utf-8");
let ast = engine.compile(script).expect(
"inbuilt method should not panic on compilation (this is a bug in california!)",
"inbuilt method should not panic on compilation (this is a bug in forn!)",
);
let method = Self::from_ast(method_name, ast, engine)?;

Expand Down Expand Up @@ -152,7 +152,7 @@ pub enum RawMethod {
/// of the names of scripts they write to avoid users of these scripts accidentally causing conflicts with scripts written by others.
///
/// E.g. if Alice writes a custom method script and distributes it on the internet with the name `powerlearn-v2`, and Bob starts using
/// it, but then later decides to use a different script made by Chloe, also called `powerlearn-v2`, California will unwittingly pass
/// it, but then later decides to use a different script made by Chloe, also called `powerlearn-v2`, Forn will unwittingly pass
/// the metadata Alice's script expected to Chloe's, at best causing it to completely fail, and at worst causing all Bob's previous
/// data to be overwritten irretrievably. This could be avoided if Alice produced `alice/powerlearn-v2` and Chloe produces
/// `chloe/powerlearn-v2`.
Expand All @@ -167,7 +167,7 @@ impl RawMethod {
///
/// # Panics
///
/// This will panic if compiling an inbuilt method fails, as this would be a bug in California. Any other failure will be
/// This will panic if compiling an inbuilt method fails, as this would be a bug in Forn. Any other failure will be
/// gracefully returned as an error.
pub fn into_method(self, engine: &Engine) -> Result<Method<'_>> {
match self {
Expand Down

0 comments on commit eaa2149

Please sign in to comment.