Giter Club home page Giter Club logo

bible-query-parser's Introduction

Bible Query Parser

This script builds on the Bible Passage Reference Parser and recommends whether to treat a given string as a passage reference or a word search.

If you're building a Bible search engine, you can use this script to decide what to do with queries that your users enter--you may want to show them a passage or search results, depending on the string.

Usage

const parseQuery = require("./bibleQueryParser.js")
const result = parseQuery("Matthew 5-7: Sermon on the Mount")
/*
{
	q: "Matthew 5-7: Sermon on the Mount",
	counts: {
		words: 1,
		osis: 1,
		book: 0,
		invalid_osis: 0
	},
	components: [
		{
			type: "osis",
			osis: "Matt.5-Matt.7",
			content: "Matthew 5-7",
			indices: [0, 11],
		},
		{
			type: "text",
			subtype: "words",
			content: ": Sermon on the Mount",
			indices: [11, 32],
		},
	],
	recommend: "osis",
}
*/

The script exports a single function, here parseQuery, that returns an object. The recommend key is osis if it suggests treating the string as a passage reference, words if it suggests treating the string as a word-search query, or error if there's a reference, but it's invalid (such as Revelation 99, which doesn't exist).

q is the original string.

counts provides a count of how many components of each type are in the string: words matches [A-Za-z\d]; osis matches valid references; book matches book names without chapters or verses; invalid_osis matches invalid passage references.

By looping through the components array, you can decide how to treat each part of the string.

Each item in components is an object with a few keys:

  • type: osis if it's an unambiguous reference; book if it's a book name without a chapter or verse (like John); invalid_osis if it looks like a reference but is invalid; or text if it doesn't look like it's related to a passage.
  • subtype if the type is text: words if it contains letters ([A-Za-z]) or numbers; space if it's whitespace; punctuation if it contains common English punctuation characters; or other if it doesn't match any of these patterns.
  • content: the actual text of the component from the string.
  • indices: the indices of the component in the string.
  • messages: passed through from the Bible Passage Reference Parser; you may be able to do something with the information here.
  • alternates: an array of alternative references in the same format as osis, in order of likelihood. For example, the query Jo 1 could refer to one of several books.

Tests

The file spec.js contains tests in Jasmine format.

bible-query-parser's People

Contributors

openbibleinfo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.