Last active
December 2, 2015 09:44
-
-
Save yosriady/c4e845ef8f2a0c30da90 to your computer and use it in GitHub Desktop.
CS3219 Snippet
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
import abc | |
class DataSource(object): | |
__metaclass__ = abc.ABCMeta | |
@abc.abstractmethod | |
def load(cls, filepath): | |
raise NotImplementedError('The load method takes in a filepath and \ | |
returns data.') |
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
import re | |
import datetime | |
from filter import Filter | |
class ExperienceFilter(Filter): | |
@classmethod | |
def run(cls, resume_attribute, query_attribute): | |
if not isinstance(query_attribute, float) or not isinstance(query_attribute, int): | |
return 0 | |
grp = re.findall('[1-2]{1}[0-9]{3}|(?<= - )current|present|now|(?<=-)current|present|now|(?<=to)current|present|now', resume_attribute, re.IGNORECASE) | |
highest = 0 | |
lowest = datetime.datetime.now().year | |
for g in grp: | |
if g == 'present' or g == 'current' or g=='now': | |
highest = datetime.datetime.now().year | |
else: | |
if int(g) < lowest: | |
lowest = int(g) | |
if int(g) > highest: | |
highest = int(g) | |
return float(highest-lowest)/query_attribute |
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
import abc | |
class Filter(object): | |
__metaclass__ = abc.ABCMeta | |
@abc.abstractmethod | |
def run(self, resume_attribute, query_attribute): | |
raise NotImplementedError('The run method takes in a resume and \ | |
a dictionary of attribute scores.') |
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
from sources.json_data_source import JSONDataSource | |
from filters.education_filter import EducationFilter | |
from filters.experience_filter import ExperienceFilter | |
from filters.skills_filter import SkillsFilter | |
from filters.languages_filter import LanguagesFilter | |
class JobMatcher(object): | |
def __init__(self, query_path, weights = {}): | |
self.query = JSONDataSource.load(query_path) | |
self.weights = weights | |
# Returns individual and total scores | |
def score(cls, resume): | |
scores = {} | |
for filter in cls.steps(): | |
attribute = filter.__name__.replace("Filter", "").lower() | |
scores[attribute] = filter.run(resume[attribute].lower(), cls.query[attribute]) | |
scores = cls.weight(scores) | |
scores['total'] = sum(scores.values()) | |
return { | |
'name': resume['name'], | |
'score': scores | |
} | |
# Declarative steps of the pipeline | |
def steps(cls): | |
return [ | |
EducationFilter, | |
ExperienceFilter, | |
SkillsFilter, | |
LanguagesFilter | |
] | |
# Returns scores weighted by user-specified weights | |
def weight(cls, scores): | |
for attribute in scores.keys(): | |
if attribute in cls.weights: | |
scores[attribute] = cls.weights[attribute] * scores[attribute] | |
return scores |
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
import abc | |
import json | |
from data_source import DataSource | |
class JSONDataSource(DataSource): | |
@classmethod | |
def load(cls, filepath): | |
with open(filepath) as data_file: | |
data = json.load(data_file) | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment