Esempio n. 1
0
def course(u=None, d=None, cid=None):
    course = app.db.query(Course).join(Department).join(University) \
            .filter(University.abbreviation==u) \
            .filter(Department.abbreviation==d) \
            .filter(Course.id==cid).first()
    if course is None:
        abort(404)
    return render_template("course.html",
            course=course,
            topics=topic_list(course, result_set=g.result_set_raw))
Esempio n. 2
0
def course(u=None, d=None, cid=None):
    course = app.db.query(Course).join(Department).join(University) \
            .filter(University.abbreviation==u) \
            .filter(Department.abbreviation==d) \
            .filter(Course.id==cid).first()
    if course is None:
        abort(404)
    return render_template("course.html",
                           course=course,
                           topics=topic_list(course,
                                             result_set=g.result_set_raw))
Esempio n. 3
0
def predicted_knowledge_areas(course, result_set=None):
    """
    Compute the set of ACM knowledge areas assigned to this course by
    determining conceptual overlap between the target course and the
    knowledge areas' inferred topics.
    """

    from trajectory.utils.vector import topic_list
    from trajectory.models import University, Department, Course
    from trajectory.models.meta import session

    # Handle empty case.
    if course is None:
        return []

    # Query database for knowledge areas.
    knowledge_areas = session.query(Department).join(University)\
            .filter(University.abbreviation=="ACM")\
            .filter(Department.abbreviation=="KA")\
            .first()

    # Handle case where ACM/KA is not present in the database.
    if knowledge_areas is None:
        raise RuntimeError("Knowledge areas not defined.")

    # This is the list of course objects representing knowledge areas.
    knowledge_areas = knowledge_areas.courses
    knowledge_areas_by_topic = {
        ka: set(topic_list(ka, result_set=result_set))
        for ka in knowledge_areas
    }

    course_topics = set(topic_list(course, result_set=result_set))

    # Generate the list of knowledge areas with conceptual overlap.
    inferred_knowledge_areas = set([
        ka for ka in knowledge_areas_by_topic
        if (course_topics & knowledge_areas_by_topic[ka])
    ])

    return inferred_knowledge_areas
Esempio n. 4
0
def predicted_knowledge_areas(course, result_set=None):
    """
    Compute the set of ACM knowledge areas assigned to this course by
    determining conceptual overlap between the target course and the
    knowledge areas' inferred topics.
    """

    from trajectory.utils.vector import topic_list
    from trajectory.models import University, Department, Course
    from trajectory.models.meta import session

    # Handle empty case.
    if course is None:
        return []

    # Query database for knowledge areas.
    knowledge_areas = session.query(Department).join(University)\
            .filter(University.abbreviation=="ACM")\
            .filter(Department.abbreviation=="KA")\
            .first()

    # Handle case where ACM/KA is not present in the database.
    if knowledge_areas is None:
        raise RuntimeError("Knowledge areas not defined.")

    # This is the list of course objects representing knowledge areas.
    knowledge_areas = knowledge_areas.courses
    knowledge_areas_by_topic = {
            ka:set(topic_list(ka, result_set=result_set))
            for ka in knowledge_areas
    }

    course_topics = set(topic_list(course, result_set=result_set))

    # Generate the list of knowledge areas with conceptual overlap.
    inferred_knowledge_areas = set([
            ka for ka in knowledge_areas_by_topic
            if (course_topics & knowledge_areas_by_topic[ka])
    ])

    return inferred_knowledge_areas
Esempio n. 5
0
def compare_departments(daid=None, dbid=None):

    if None in [daid, dbid]:
        departments = app.db.query(Department).all()
        return render_template("compare_departments_landing.html",
                               departments=departments)

    # Look up references to requested departments.
    department_a = app.db.query(Department).get(daid)
    department_b = app.db.query(Department).get(dbid)

    # If either department isn't found, or if there is no result set
    # (meaning no topics to infer) then simply 404.
    if department_a is None or department_b is None or g.result_set_raw is None:
        abort(404)

    # Identify a set of topics for each department.
    department_a_topics = set(topic_list(department_a, g.result_set_raw))
    department_b_topics = set(topic_list(department_b, g.result_set_raw))

    # Generate topic vectors for the two departments.
    a_vector = topic_vector(department_a, g.result_set_raw)
    b_vector = topic_vector(department_b, g.result_set_raw)
    a_vector_string = a_vector.unpack(one=b'1', zero=b'0').decode('utf-8')
    b_vector_string = b_vector.unpack(one=b'1', zero=b'0').decode('utf-8')

    # Run similarity metrics.
    similarity = dict()
    similarity['jaccard'] = {
        'name': 'Jaccard Index',
        'range': '[0, 1]',
        'description': 'Comparative set cardinality.',
        'value': jaccard(department_a_topics, department_b_topics),
    }
    similarity['cosine'] = {
        'name': 'Cosine Similarity',
        'range': '[-1, 1]',
        'description': 'Geometric cosine distance.',
        'value': cosine_similarity(a_vector, b_vector),
    }
    similarity['euclidean'] = {
        'name': 'Euclidean Distance',
        'description': 'Geometric vector distance.',
        'value': euclidean_distance(a_vector, b_vector),
    }

    # Remove common topics from the topic sets.
    intersection = department_a_topics & department_b_topics
    department_a_topics = department_a_topics - intersection
    department_b_topics = department_b_topics - intersection

    # Number of courses in each department.
    num_courses_a = app.db.query(Course).join(Department) \
            .filter(Department.id==daid).count()
    num_courses_b = app.db.query(Course).join(Department) \
            .filter(Department.id==dbid).count()

    # Global list of departments for switching over.
    departments = app.db.query(Department).all()

    return render_template(
        "compare_departments.html",
        da=department_a,
        db=department_b,
        da_topics=department_a_topics,
        db_topics=department_b_topics,
        num_courses_a=num_courses_a,
        num_courses_b=num_courses_b,
        common_topics=intersection,
        departments=departments,
        similarity_metrics=similarity,
        da_vector=a_vector_string,
        db_vector=b_vector_string,
    )
Esempio n. 6
0
def compare(depA, depB, rs):
    dep_a_topics = topic_list(depA, rs)
    dep_b_topics = topic_list(depB, rs)
    return jaccard(dep_a_topics, dep_b_topics)
Esempio n. 7
0
def compare_departments(daid=None, dbid=None):

    if None in [daid, dbid]:
        departments = app.db.query(Department).all()
        return render_template("compare_departments_landing.html",
                departments=departments)

    # Look up references to requested departments.
    department_a = app.db.query(Department).get(daid)
    department_b = app.db.query(Department).get(dbid)

    # If either department isn't found, or if there is no result set
    # (meaning no topics to infer) then simply 404.
    if department_a is None or department_b is None or g.result_set_raw is None:
        abort(404)

    # Identify a set of topics for each department.
    department_a_topics = set(topic_list(department_a, g.result_set_raw))
    department_b_topics = set(topic_list(department_b, g.result_set_raw))

    # Generate topic vectors for the two departments.
    a_vector = topic_vector(department_a, g.result_set_raw)
    b_vector = topic_vector(department_b, g.result_set_raw)
    a_vector_string = a_vector.unpack(one=b'1', zero=b'0').decode('utf-8')
    b_vector_string = b_vector.unpack(one=b'1', zero=b'0').decode('utf-8')

    # Run similarity metrics.
    similarity = dict()
    similarity['jaccard'] = {
            'name': 'Jaccard Index',
            'range': '[0, 1]',
            'description': 'Comparative set cardinality.',
            'value': jaccard(department_a_topics, department_b_topics),
    }
    similarity['cosine'] = {
            'name': 'Cosine Similarity',
            'range': '[-1, 1]',
            'description': 'Geometric cosine distance.',
            'value': cosine_similarity(a_vector, b_vector),
    }
    similarity['euclidean'] = {
            'name': 'Euclidean Distance',
            'description': 'Geometric vector distance.',
            'value': euclidean_distance(a_vector, b_vector),
    }

    # Remove common topics from the topic sets.
    intersection = department_a_topics & department_b_topics
    department_a_topics = department_a_topics - intersection
    department_b_topics = department_b_topics - intersection

    # Number of courses in each department.
    num_courses_a = app.db.query(Course).join(Department) \
            .filter(Department.id==daid).count()
    num_courses_b = app.db.query(Course).join(Department) \
            .filter(Department.id==dbid).count()

    # Global list of departments for switching over.
    departments = app.db.query(Department).all()

    return render_template("compare_departments.html",
            da=department_a,
            db=department_b,

            da_topics=department_a_topics,
            db_topics=department_b_topics,

            num_courses_a=num_courses_a,
            num_courses_b=num_courses_b,

            common_topics=intersection,

            departments=departments,

            similarity_metrics=similarity,

            da_vector=a_vector_string,
            db_vector=b_vector_string,
    )