Commit 9a7970a0 authored by Zach Perkins's avatar Zach Perkins
Browse files

Added a list of common substitutions

parent 89cdfb63
# Replaces various strings with other strings when needed
module CourseReplacementHelper
@@replacements = {
"BIO"=> "BIOL",
"HONORS"=>"_HONORS_", # Sometimes the honors will be in parenthesis so this accounts for that
"ACADEMIC ENGLISH"=> "AE",
"ACCOUNTING"=> "ACCT",
"AFRICAN AND AFRICAN AMERICAN STUDIES"=> "AFAM",
"ANTHROPOLOGY"=> "ANTH",
"APPLIED INFORMATION TECHNOLOGY"=> "AIT",
"ARABIC"=> "ARAB",
"ART AND VISUAL TECHNOLOGY"=> "AVT",
"ART HISTORY"=> "ARTH",
"ARTS MANAGEMENT"=> "AMGT",
"ASSISTIVE TECHNOLOGY"=> "EDAT",
"ASTRONOMY"=> "ASTR",
"ATHLETIC TRAINING EDUCATION PROGRAM"=> "ATEP",
"BACHELOR OF INDIVIDUALIZED STUDY"=> "BIS",
"BACHELOR'S OF APPLIED SCIENCE"=> "BAS",
"BIODEFENSE"=> "BIOD",
"BIOENGINEERING"=> "BENG",
"BIOINFORMATICS"=> "BINF",
"BIOLOGY"=> "BIOL",
"BIOMEDICAL SCIENCES"=> "BMED",
"BIOSCIENCES"=> "BIOS",
"BUSINESS AND LEGAL STUDIES"=> "BULE",
"BUSINESS"=> "BUS",
"BUSINESS MANAGEMENT"=> "BMGT",
"BUSINESS MANAGEMENT OF SECURE INFORMATION SYSTEMS"=> "MSIS",
"CHEMISTRY"=> "CHEM",
"CHINESE"=> "CHIN",
"CIVIL AND INFRASTRUCTURE ENGINEERING"=> "CEIE",
"CLASSICS"=> "CLAS",
"CLIMATE DYNAMICS"=> "CLIM",
"COLLEGE OF SCIENCE"=> "COS",
"COLLEGE OF VISUAL AND PERFORMING ARTS"=> "CVPA",
"COMMUNICATION"=> "COMM",
"COMPUTATIONAL AND DATA SCIENCES"=> "CDS",
"COMPUTATIONAL SCIENCE AND INFORMATICS"=> "CSI",
"COMPUTATIONAL SOCIAL SCIENCE"=> "CSS",
"COMPUTER FORENSICS"=> "CFRS",
"COMPUTER GAME DESIGN"=> "GAME",
"COMPUTER SCIENCE"=> "CS",
"COMP SCI"=> "CS",
"CONFLICT ANALYSIS AND RESOLUTION"=> "CONF",
"CONSERVATION STUDIES"=> "CONS",
"COUNSELING AND DEVELOPMENT"=> "EDCD",
"CRIMINOLOGY"=> "CRIM",
"CULTURAL STUDIES"=> "CULT",
"CURRICULUM AND INSTRUCTION"=> "EDCI",
"CYBER SECURITY ENGINEERING"=> "CYSE",
"DANCE"=> "DANC",
"DATA ANALYTICS ENGINEERING"=> "DAEN",
"EARLY CHILDHOOD EDUCATION"=> "ECED",
"ECONOMICS"=> "ECON",
"EDUCATIONAL PSYCHOLOGY"=> "EDEP",
"EDUCATION"=> "EDUC",
"EDUCATION INSTRUCTIONAL TECHNOLOGY"=> "EDIT",
"EDUCATION LEADERSHIP"=> "EDLE",
"EDUCATION RESEARCH"=> "EDRS",
"ELECTRICAL AND COMPUTER ENGINEERING"=> "ECE",
"ENGINEERING"=> "ENGR",
"ENGLISH"=> "ENGH",
"ENGLISH FOR ACADEMIC PURPOSES"=> "EAP",
"ENVIRONMENTAL SCIENCE AND POLICY"=> "EVPP",
"EXECUTIVE MBA"=> "EMBA",
"EXERCISE, FITNESS, AND HEALTH PROMOTION"=> "EFHP",
"FILM AND VIDEO STUDIES"=> "FAVS",
"FINANCE"=> "FNAN",
"FOREIGN LANGUAGE"=> "FRLN",
"FORENSIC SCIENCE"=> "FRSC",
"FRENCH"=> "FREN",
"GEOGRAPHY AND GEOINFORMATION SCIENCE"=> "GGS",
"GEOLOGY"=> "GEOL",
"GERMAN"=> "GERM",
"GLOBAL AFFAIRS"=> "GLOA",
"GLOBAL AND COMMUNITY HEALTH"=> "GCH",
"GOVERNMENT"=> "GOVT",
"GRADUATE SCHOOL OF BUSINESS"=> "GBUS",
"GREEK"=> "GREE",
"HEALTH ADMINISTRATION AND POLICY"=> "HAP",
"HEALTH AND HUMAN SERVICES"=> "HHS",
"HEALTH"=> "HEAL",
"HEBREW"=> "HEBR",
"HIGHER EDUCATION"=> "HE",
"HISTORY"=> "HIST",
"HONORS COLLEGE"=> "HNRS",
"HUMAN DEVELOPMENT AND FAMILY SCIENCE"=> "HDFS",
"INFORMATION SECURITY ASSURANCE"=> "ISA",
"INFORMATION SYSTEMS"=> "INFS",
"INFORMATION TECHNOLOGY"=> "IT",
"INITIATIVES IN EDUCATIONAL TRANSFORMATION-TEACHING"=> "IETT",
"INTEGRATIVE STUDIES"=> "INTS",
"INTERDISCIPLINARY STUDIES"=> "MAIS",
"INTERNATIONAL COMMERCE AND POLICY"=> "ITRN",
"INTERNATIONAL YEAR ONE"=> "INYO",
"ITALIAN"=> "ITAL",
"JAPANESE"=> "JAPA",
"KINESIOLOGY"=> "KINE",
"KOREAN"=> "KORE",
"LATIN AMERICAN STUDIES"=> "LAS",
"LATIN"=> "LATN",
"LINGUISTICS"=> "LING",
"MANAGEMENT"=> "MGMT",
"MANAGEMENT OF INFORMATION SYSTEMS"=> "MIS",
"MANAGEMENT OF SECURE INFORMATION SYSTEMS"=> "MSEC",
"MARKETING"=> "MKTG",
"MATHEMATICS"=> "MATH",
"MECHANICAL ENGINEERING"=> "ME",
"MEDICAL LABORATORY SCIENCE"=> "MLAB",
"MIDDLE EAST AND ISLAMIC STUDIES"=> "MEIS",
"MILITARY SCIENCE"=> "MLSC",
"MINOR IN BUSINESS"=> "MBUS",
"MUSIC"=> "MUSI",
"NANOTECHNOLOGY AND NANOSCIENCE"=> "NANO",
"NATIVE AMERICAN AND INDIGENOUS STUDIES"=> "NAIS",
"NEUROSCIENCE"=> "NEUR",
"NURSING"=> "NURS",
"NUTRITION AND FOOD STUDIES"=> "NUTR",
"OPERATIONS MANAGEMENT"=> "OM",
"OPERATIONS RESEARCH"=> "OR",
"ORGANIZATION DEVELOPMENT AND KNOWLEDGE MANAGEMENT"=> "ODKM",
"PARKS, RECREATION, AND LEISURE STUDIES"=> "PRLS",
"PERSIAN"=> "PERS",
"PHILOSOPHY"=> "PHIL",
"PHYSICAL EDUCATION"=> "PHED",
"PHYSICS"=> "PHYS",
"POLICY AND GOVERNMENT"=> "POGO",
"PORTUGUESE"=> "PORT",
"PROFESSIONAL DEVELOPMENT IN EDUCATION"=> "EDPD",
"PROVOST"=> "PROV",
"PSYCHOLOGY"=> "PSYC",
"PUBLIC ADMINISTRATION"=> "PUAD",
"PUBLIC POLICY"=> "PUBP",
"READING"=> "EDRD",
"REAL ESTATE DEVELOPMENT"=> "REAL",
"RECREATION"=> "RECR",
"REHABILITATION SCIENCE"=> "RHBS",
"RELIGIOUS STUDIES"=> "RELI",
"RUSSIAN"=> "RUSS",
"SCHOOL OF MANAGEMENT"=> "SOM",
"SCHOOL PSYCHOLOGY"=> "SPSY",
"SOCIAL WORK"=> "SOCW",
"SOCIOLOGY AND ANTHROPOLOGY"=> "SOAN",
"SOCIOLOGY"=> "SOCI",
"SOFTWARE ENGINEERING"=> "SWE",
"SPANISH"=> "SPAN",
"SPECIAL EDUCATION"=> "EDSE",
"SPORT MANAGEMENT"=> "SPMT",
"SPORTS AND RECREATION STUDIES"=> "SRST",
"STATISTICS"=> "STAT",
"SYSTEM ENGINEERING"=> "SYST",
"SYSTEMS ENGINEERING AND OPERATIONS RESEARCH"=> "SEOR",
"TECHNOLOGY MANAGEMENT"=> "TECM",
"TELECOMMUNICATIONS"=> "TCOM",
"THEATER"=> "THR",
"TOURISM AND EVENTS MANAGEMENT"=> "TOUR",
"TURKISH"=> "TURK",
"UNIVERSITY STUDIES"=> "UNIV",
"URBAN AND SUBURBAN STUDIES"=> "USST",
"VOLGENAU SCHOOL OF ENGINEERING"=> "VSE",
"WOMEN AND GENDER STUDIES"=> "WMS",
"1"=> "I",
"2"=> "II",
"3"=> "III",
"4"=> "IV",
"5"=> "V"
}
def self.replace!(input)
@@replacements.each do |thing, replacement|
# We want each instance of thing to be it's own word
input.gsub!(/(?<= |^)#{thing}(?= |$)/, replacement)
end
end
end
\ No newline at end of file
# Contains logic regarding the +Course+ model.
#
# TODO: Add more docs
require("course_replacement_helper.rb")
class Course < ApplicationRecord
# Each course belongs to a +Semester+
belongs_to :semester
......@@ -26,8 +29,9 @@ class Course < ApplicationRecord
end
def self.from_title(base_query, title)
puts title
# Temporary really disgusting regex that I hate with all my heart
title = (title + " ").gsub(" 1", " I").gsub(" 2", " II").gsub(" 3", " III").upcase.gsub(/(I+) +/, '\1$').gsub(/ +/, "% ").tr('$', ' ')
title = (title + " ").upcase.gsub(/(I+) +/, '\1$').gsub(/ +/, "% ").tr('$', ' ')
base_query.where("UPPER(courses.title) LIKE UPPER(?) or UPPER(courses.title) LIKE UPPER(?)", "%#{title.strip}", "%#{title}%")
end
......@@ -57,12 +61,28 @@ class Course < ApplicationRecord
# Splits a generic string (i.e. "CS 211") into a series of components that can
# be used to run a query with fetch()
def self.parse_generic_query(query)
# In the future when there is more info, this will be more complex to
# include class names/descriptions
query.upcase!
CourseReplacementHelper.replace!(query)
filters = {}
q = query.delete(" ")
/[a-zA-Z]+/.match(q) { |a| filters["subject"] = a.to_s }
/\d+/.match(q) { |a| filters["course_number"] = a.to_s }
query.scan(/(?<= |^)([a-zA-Z]{2,4})(?=$| )/).each do |a|
s = a[0]
if from_subject(select("*"), s).count > 0
filters["subject"] = s
query.remove!(s)
end
end
query.scan(/(?<= |^)(\d{3})(?=$| )/).each do |a|
s = a[0]
if filters.include? "subject" and from_course_number(from_subject(select("*"), filters["subject"]), s).count > 0
filters["course_number"] = s
query.remove!(s)
return filters
end
end
filters["title"] = query.gsub(/ +/, " ").strip
filters
end
end
class Instructor < ApplicationRecord
has_many :course_sections
def self.named(name)
where("name LIKE ?", "%#{name}%")
def self.named(base_query, name)
base_query.where("name LIKE ?", "%#{name}%")
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment