-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from MITLibraries/tco-82-knowledge-graph
Implement Detector, Category, DetectorCategory
- Loading branch information
Showing
20 changed files
with
360 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: categories | ||
# | ||
# id :integer not null, primary key | ||
# name :string | ||
# description :text | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class Category < ApplicationRecord | ||
has_many :detector_categories, dependent: :destroy | ||
has_many :detectors, through: :detector_categories | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
# Detectors are classes that implement various algorithms that allow us to identify patterns | ||
# within search terms. | ||
module Detector | ||
def self.table_name_prefix | ||
'detector_' | ||
end | ||
# == Schema Information | ||
# | ||
# Table name: detectors | ||
# | ||
# id :integer not null, primary key | ||
# name :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class Detector < ApplicationRecord | ||
has_many :detector_categories, dependent: :destroy | ||
has_many :categories, through: :detector_categories | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: detector_categories | ||
# | ||
# id :integer not null, primary key | ||
# detector_id :integer not null | ||
# category_id :integer not null | ||
# confidence :float | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class DetectorCategory < ApplicationRecord | ||
belongs_to :category | ||
belongs_to :detector | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateCategories < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :categories do |t| | ||
t.string :name | ||
t.text :description | ||
|
||
t.timestamps | ||
end | ||
add_index :categories, :name, unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateDetectors < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :detectors do |t| | ||
t.string :name | ||
|
||
t.timestamps | ||
end | ||
add_index :detectors, :name, unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateDetectorCategories < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :detector_categories do |t| | ||
t.belongs_to :detector, null: false, foreign_key: true | ||
t.belongs_to :category, null: false, foreign_key: true | ||
t.float :confidence | ||
|
||
t.timestamps | ||
end | ||
add_index :detector_categories, [:detector_id, :category_id] | ||
add_index :detector_categories, [:category_id, :detector_id] | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# == Schema Information | ||
# | ||
# Table name: categories | ||
# | ||
# id :integer not null, primary key | ||
# name :string | ||
# description :text | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
informational: | ||
name: 'Informational' | ||
description: '...' | ||
|
||
navigational: | ||
name: 'Navigational' | ||
description: '...' | ||
|
||
transactional: | ||
name: 'Transactional' | ||
description: '...' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# == Schema Information | ||
# | ||
# Table name: detector_categories | ||
# | ||
# id :integer not null, primary key | ||
# detector_id :integer not null | ||
# category_id :integer not null | ||
# confidence :float | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
one: | ||
detector: doi | ||
category: transactional | ||
confidence: 0.95 | ||
|
||
two: | ||
detector: isbn | ||
category: transactional | ||
confidence: 0.95 | ||
|
||
three: | ||
detector: issn | ||
category: transactional | ||
confidence: 0.95 | ||
|
||
four: | ||
detector: pmid | ||
category: transactional | ||
confidence: 0.95 | ||
|
||
five: | ||
detector: journal | ||
category: transactional | ||
confidence: 0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# == Schema Information | ||
# | ||
# Table name: detectors | ||
# | ||
# id :integer not null, primary key | ||
# name :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
doi: | ||
name: 'DOI' | ||
|
||
isbn: | ||
name: 'ISBN' | ||
|
||
issn: | ||
name: 'ISSN' | ||
|
||
pmid: | ||
name: 'PMID' | ||
|
||
journal: | ||
name: 'Journal' | ||
|
||
suggestedresource: | ||
name: 'SuggestedResource' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: categories | ||
# | ||
# id :integer not null, primary key | ||
# name :string | ||
# description :text | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
require 'test_helper' | ||
|
||
class CategoryTest < ActiveSupport::TestCase | ||
test 'duplicate Categories are not allowed' do | ||
initial_count = Category.count | ||
Category.create!(name: 'Example') | ||
assert_equal(initial_count + 1, Category.count) | ||
|
||
assert_raises(ActiveRecord::RecordNotUnique) do | ||
Category.create!(name: 'Example') | ||
end | ||
end | ||
|
||
test 'destroying a Category will delete associated DetectorCategories' do | ||
category_count = Category.count | ||
link_count = DetectorCategory.count | ||
record = categories('transactional') | ||
link_category = record.detector_categories.count | ||
|
||
record.destroy | ||
|
||
assert_equal(category_count - 1, Category.count) | ||
assert_equal(link_count - link_category, DetectorCategory.count) | ||
end | ||
|
||
test 'destroying a Category will not delete associated Detectors' do | ||
category_count = Category.count | ||
detector_count = Detector.count | ||
record = categories('transactional') | ||
|
||
record.destroy | ||
|
||
assert_equal(category_count - 1, Category.count) | ||
assert_equal(detector_count, Detector.count) | ||
end | ||
end |
Oops, something went wrong.