Skip to content

Commit 3cea65a

Browse files
Merge pull request #101 from MITLibraries/tco-82-knowledge-graph
Implement Detector, Category, DetectorCategory
2 parents 02fc057 + b770c25 commit 3cea65a

20 files changed

Lines changed: 360 additions & 16 deletions

app/dashboards/detector/suggested_resource_dashboard.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'administrate/base_dashboard'
44

5-
module Detector
5+
class Detector
66
class SuggestedResourceDashboard < Administrate::BaseDashboard
77
# ATTRIBUTE_TYPES
88
# a hash that describes the type of each of the model's fields.

app/models/category.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
# == Schema Information
4+
#
5+
# Table name: categories
6+
#
7+
# id :integer not null, primary key
8+
# name :string
9+
# description :text
10+
# created_at :datetime not null
11+
# updated_at :datetime not null
12+
#
13+
class Category < ApplicationRecord
14+
has_many :detector_categories, dependent: :destroy
15+
has_many :detectors, through: :detector_categories
16+
end

app/models/detector.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# frozen_string_literal: true
22

3-
# Detectors are classes that implement various algorithms that allow us to identify patterns
4-
# within search terms.
5-
module Detector
6-
def self.table_name_prefix
7-
'detector_'
8-
end
3+
# == Schema Information
4+
#
5+
# Table name: detectors
6+
#
7+
# id :integer not null, primary key
8+
# name :string
9+
# created_at :datetime not null
10+
# updated_at :datetime not null
11+
#
12+
class Detector < ApplicationRecord
13+
has_many :detector_categories, dependent: :destroy
14+
has_many :categories, through: :detector_categories
915
end

app/models/detector/journal.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
# created_at :datetime not null
1111
# updated_at :datetime not null
1212
#
13-
module Detector
13+
class Detector
1414
# Detector::Journal stores information about academic journals loaded from external sources to allow us to check our
1515
# incoming Terms against these information
1616
class Journal < ApplicationRecord
1717
before_save :downcase_fields!
1818

19+
def self.table_name_prefix
20+
'detector_'
21+
end
22+
1923
# Identify journals in which the incoming phrase matches a Journal.name exactly
2024
#
2125
# @note We always store the Journal.name downcased, so we should also always downcase the phrase

app/models/detector/standard_identifiers.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# frozen_string_literal: true
22

3-
module Detector
3+
class Detector
44
# Detector::StandardIdentifiers detects the identifiers DOI, ISBN, ISSN, PMID.
55
# See /docs/reference/pattern_detection_and_enhancement.md for details.
66
class StandardIdentifiers
77
attr_reader :identifiers
88

9+
def self.table_name_prefix
10+
'detector_'
11+
end
12+
913
def initialize(term)
1014
@identifiers = {}
1115
term_pattern_checker(term)

app/models/detector/suggested_resource.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515

1616
require 'stringex/core_ext'
1717

18-
module Detector
18+
class Detector
1919
# Detector::SuggestedResource stores custom hints that we want to send to the
2020
# user in response to specific strings. For example, a search for "web of
2121
# science" should be met with our custom login link to Web of Science via MIT.
2222
class SuggestedResource < ApplicationRecord
2323
before_save :update_fingerprint
2424

25+
def self.table_name_prefix
26+
'detector_'
27+
end
28+
2529
# This exists for the before_save lifecycle hook to call the calculate_fingerprint method, to ensure that these
2630
# records always have a correctly-calculated fingerprint. It has no arguments and returns nothing.
2731
def update_fingerprint

app/models/detector_category.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# == Schema Information
4+
#
5+
# Table name: detector_categories
6+
#
7+
# id :integer not null, primary key
8+
# detector_id :integer not null
9+
# category_id :integer not null
10+
# confidence :float
11+
# created_at :datetime not null
12+
# updated_at :datetime not null
13+
#
14+
class DetectorCategory < ApplicationRecord
15+
belongs_to :category
16+
belongs_to :detector
17+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CreateCategories < ActiveRecord::Migration[7.1]
2+
def change
3+
create_table :categories do |t|
4+
t.string :name
5+
t.text :description
6+
7+
t.timestamps
8+
end
9+
add_index :categories, :name, unique: true
10+
end
11+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateDetectors < ActiveRecord::Migration[7.1]
2+
def change
3+
create_table :detectors do |t|
4+
t.string :name
5+
6+
t.timestamps
7+
end
8+
add_index :detectors, :name, unique: true
9+
end
10+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class CreateDetectorCategories < ActiveRecord::Migration[7.1]
2+
def change
3+
create_table :detector_categories do |t|
4+
t.belongs_to :detector, null: false, foreign_key: true
5+
t.belongs_to :category, null: false, foreign_key: true
6+
t.float :confidence
7+
8+
t.timestamps
9+
end
10+
add_index :detector_categories, [:detector_id, :category_id]
11+
add_index :detector_categories, [:category_id, :detector_id]
12+
end
13+
end

0 commit comments

Comments
 (0)