imonroe / corpora
A PHP-friendly version of the dariusk/corpora javascript library. It provides "[a] collection of small corpuses of interesting data for the creation of bots and similar stuff"
Requires
- php: ^7.0|^8.0
- squizlabs/php_codesniffer: ^3.6
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-11-12 00:15:20 UTC
README
This is a PHP- and Composer-friendly fork of the darius/corpora
package, designed for easy use with PHP projects.
Check the files in the /data
directory to find out all the things in the corpora. Each JSON file is an array with about a thousand examples of whatever you're asking for.
Installation
composer require imonroe/corpora
Usage
use imonroe\corpora\Corpora;
$corpora = new Corpora;
\\ Returns an array of available categories
$categories = $corpora->getCategories();
// Returns an array of subcategories
$subcategories = $corpora->getCategories('architecture');
// Return just the description of a given data file, if one is available.
$description = $corpora->getDescription('words.nouns');
// $description == "A list of English nouns."
// Returns an array of data from the corpora.
// Specify the file you want in the form of "dirname.dirname.filename"
// Do not include the .json extension.
// Available files are included in the \data directory of this repo.
// for instance, if you wanted the contents of the ./data/words/nouns.json file, you'd
// request it like this:
$nouns = $corpora->getDataFile('words.nouns');
// If you want ./data/music/genres.json, you'd call it like:
$genres = $corpora->getDataFile('music.genres');
// If you want ./data/societies_and_groups/fraternities/fraternities.json,
$fraternities = $corpora->getDataFile('societies_and_groups.fraternities.fraternities');
// You can inspect any of these arrays in the usual way to find out what they contain.
Testing
composer test
Styling
composer check-style
and
composer fix-style
Original darius/corpora
README:
Corpora
This project is a collection of static corpora (plural of "corpus") that are potentially useful in the creation of weird internet stuff. I've found that, as a creator, sometimes I am making something that needs access to a lot of adjectives, but not necessarily every adjective in the English language. So for the last year I've been copy/pasting an adjs.json
file from project to project. This is kind of awful, so I'm hoping that this project will at least help me keep everything in one place.
I would like this to help with rapid prototyping of projects. For example: you might use nouns.json
to start with, just to see if an idea you had was any good. Once you've built the project quickly around the nouns collection, you can then rip it out and replace it with a more complex or exhaustive data source.
I'm also hoping that this can be used as a teaching tool: maybe someone has three hours to teach how to make Twitter bots. That doesn't give the student much time to find/scrape/clean/parse interesting data. My hope is that students can be pointed to this project and they can pick and choose different interesting data sources to meld together for the creation of prototypes.
License
Since Corpora is more data than code, I have chosen to CC0 license this (rather than MIT license or similar).
To the extent possible under law, Darius Kazemi has waived all copyright and related or neighboring rights to Corpora. This work is published from: United States.
What is Corpora NOT?
This project is not meant to replace exhaustive APIs -- if you want nouns, and you want every noun in the English language, replete with metadata, consider Wordnik. If you want the title of every Wikipedia article, use the MediaWiki API.
What is Corpora?
- Corpora is a repository of JSON files, meant to be language-neutral. If you want to create an NPM repo or whatever based on this, be my guest, but this repository will remain a collection of data files that can be interpreted by any language that can parse JSON.
- Corpora is a collection of small files. It is not meant to be an exhaustive source of anything: a list of resources should contain somewhere in the vicinity of 1000 items.
- For example, Corpora will not contain any complete "dictionary" style files. Instead we host a sampling of 1000 common nouns, adjectives, and verbs.
- Some lists are small enough by nature that we may contain a complete list of things in their category. For example, a list of heavily populated U.S. cities may only have 75 cities and be considered complete.
List of Corpora-related tools
- corpora-project, a Node.js NPM package for accessing corpora data offline.
- pycorpora, a simple Python interface for corpora
- corpora-api, a Node.js server that offers up the corpora as a JSON API (now live at https://corpora-api.glitch.me)
I have some data, how do I submit?
We accept pull requests to this repository. Some guidelines:
- BY SUBMITTING DATA AS A PULL REQUEST, YOU AGREE TO OUR APPLYING A CC0 FREE CULTURE LICENSE TO THE DATA, MEANING THAT ANYONE CAN USE THE DATA FOR ANY REASON WITHOUT ATTRIBUTION IN PERPETUITY.
- Please submit all data as JSON format in a file with a
.json
extension, and please JSONLint your files before submitting -- also, thanks to Matt Rothenberg we have Travis-CI testing, which will jsonlint your pull request automatically. If you see a test failure notification in your PR after you submit, there's a problem with your JSON! - Keep individual files to about 1000 "things" maximum. Fewer than 1000 is fine, too.
- If you'd like attribution, I'm happy to include your name in this Readme file. Just remember that nobody who uses this data is obligated to include attribution in their own projects.