示例#1
0
def getMatchingKnowledgeArea(candidate):
    # find matching knowledge area and return Id

    for knowledgearea in knowledgeAreas:
        if knowledgearea.getText().strip() == str(candidate).strip():
            return knowledgearea

    return KnowledgeArea()
示例#2
0
def ExtractKnowledgeAreas(firebase, document, knowledgeAreas):
    # find the knowledge areas in the document and write them to a database table

    global firstPositionOfCKA
    firstPositionOfCKA = 0

    for i, p in enumerate(document.paragraphs):
        pText = p.text.strip()
        lastPos = len(pText)
        kaText = ""

        isKnowledgeArea, kaText = ParagraphIsKnowledgeArea(
            document, p, i, lastPos, pText)

        if isKnowledgeArea == 'true' and kaText:
            knowledgeArea = KnowledgeArea()
            knowledgeArea.setText(kaText)
            knowledgeAreas.append(knowledgeArea)

        diff = (i - firstPositionOfCKA)
        if firstPositionOfCKA > 0 and diff > 120:
            break

    for knowledgeArea in knowledgeAreas:
        newKnowledgeArea = {'Content': knowledgeArea.getText()}
        result = firebase.post('KnowledgeArea', newKnowledgeArea)
        knowledgeArea.setId(result.get("name"))
示例#3
0
def FindKnowledgeAreaId(KnowledgeAreaText: str) -> str:
    """
        Find existing KnowledgeArea in the global collection.
        If found, get the Id.

        :param newKnowledgeArea: a KnowledgeArea object

        :return string representation of the Id

    """

    global knowledgeAreas

    for KnowledgeArea in knowledgeAreas:
        if KnowledgeArea.getText().strip().lower() == KnowledgeAreaText.strip(
        ).lower():
            return KnowledgeArea.getId()

    return ""
示例#4
0
def GetKnowledgeAreas(firebase: firebase) -> None:
    """
        Get  KnowledgeAreas from the database and
        insert them into the global collection.

        :param firebase: a firebase connection

    """

    global knowledgeAreas

    obj_key_list = []

    result = firebase.get('/knowledgearea', None)

    if result is None:
        return

    for i in result.keys():
        obj_key_list.append(i)

    for i in obj_key_list:
        knowledgeArea = KnowledgeArea()
        knowledgeArea.setText(result[i]['content'])
        knowledgeArea.setId(i)
        knowledgeAreas.append(knowledgeArea)
示例#5
0
def GetExistingKnowledgeAreas(firebase: firebase, document: Document) -> None:
    """
        Get existing KnowledgeAreas from the database and
        insert them into the global collection.

        :param firebase: a firebase connection
        :param document: a Python-Docx Document object

    """

    global existingKnowledgeAreas

    obj_key_list = []

    result = firebase.get('/knowledgearea', None)

    if result is None:
        return

    for i in result.keys():
        obj_key_list.append(i)

    for i in obj_key_list:
        knowledgeArea = KnowledgeArea()
        knowledgeArea.setText(result[i]['content'])
        knowledgeArea.setId(i)
        existingKnowledgeAreas.append(knowledgeArea)
示例#6
0
def getMatchingKnowledgeArea(candidate: str) -> KnowledgeArea:
    """
        Find matching knowledge area and return the Knowledge Area as a string.

        :param candidate: a string representing an extracted paragraph that
         we want to check to see if it matches a Knowledge Area.
    """

    for knowledgearea in knowledgeAreas:
        if knowledgearea.getText().strip() == str(candidate).strip():
            return knowledgearea

    return KnowledgeArea()
示例#7
0
def ExtractKnowledgeAreas(firebase: firebase, document: Document, knowledgeAreas: List[KnowledgeArea]) -> None:
    """
        Find the KnowledgeAreas in the document and
        insert them into a database table.

        :param firebase: a firebase connection
        :param document: a Python-Docx Document object
        :param knowledgeAreas: a List of KnowledgeArea objects

    """

    global firstPositionOfCKA
    firstPositionOfCKA = 0

    for i, p in enumerate(document.paragraphs):
        pText = p.text.strip()
        lastPos = len(pText)
        kaText = ""

        isKnowledgeArea, kaText = ParagraphIsKnowledgeArea(document, p, i, lastPos, pText)

        if isKnowledgeArea and kaText:
            knowledgeArea = KnowledgeArea()
            knowledgeArea.setText(kaText)
            knowledgeAreas.append(knowledgeArea)

        diff = (i - firstPositionOfCKA)
        if firstPositionOfCKA > 0 and diff > 120:
            break

    for knowledgeArea in knowledgeAreas:
        newKnowledgeArea = {
            'content': knowledgeArea.getText()
        }

        existingKey = FindExistingKnowledgeAreaId(knowledgeArea)

        if existingKey == "":
            result = firebase.post('knowledgearea', newKnowledgeArea)
            knowledgeArea.setId(result.get("name"))
        else:
            knowledgeArea.setId(existingKey)
示例#8
0
def writeCourseRows(ws: xlsxwriter.worksheet,
                    knowledgeArea: KnowledgeArea) -> None:
    """

        Write the rows in the courses worksheet for all courses under
        the knowledgearea.

        :param ws: Excel Worksheet Object
        :param knowledgeArea: KnowledgeArea

    """

    global courses
    global coursesWsRow

    col = 0
    knowledgeAreaId = knowledgeArea.getId()

    for course in courses:
        if str(course.getKnowledgeAreaId()) == str(knowledgeAreaId):
            ws.write(coursesWsRow, col, knowledgeArea.getText())
            col += 1

            courseId = course.getId()
            ws.write(coursesWsRow, col, courseId)
            col += 1
            ws.write(coursesWsRow, col, course.getTitle())
            col += 2
            ws.write(coursesWsRow, col, course.getDescription())
            col += 2
            ws.write(coursesWsRow, col, course.getInstructor())
            col += 2
            ws.write(coursesWsRow, col, course.getFee())

            coursesWsRow += 1
            col = 0
示例#9
0
def FindExistingKnowledgeAreaId(newKnowledgeArea: KnowledgeArea) -> str:
    """
        Find existing KnowledgeArea in the global collection.
        If found, get the Id.

        :param newKnowledgeArea: a KnowledgeArea object

        :return string representation of the Id

    """

    global existingKnowledgeAreas

    for existingKnowledgeArea in existingKnowledgeAreas:
        if existingKnowledgeArea.getText() == newKnowledgeArea.getText():
            return existingKnowledgeArea.getId()

    return ""
示例#10
0
from textblob import TextBlob
from firebase import firebase

from catalog import Catalog
from knowledgearea import KnowledgeArea
from course import Course
from learningobjective import LearningObjective
from learningobjective_course import LearningObjective_course
from paragraph import Paragraph
import constant
import time

existingCatalogRecords = []
existingKnowledgeAreas = []
firstPositionOfCKA = 0
currentKnowledgeArea = KnowledgeArea()
courseNameStyles = [constant.STYLE_NORMAL, constant.STYLE_HEADING, constant.STYLE_HEADING7]

firebase = firebase.FirebaseApplication('https://scholacity-org.firebaseio.com/')

document = Document('../Catalogs/Fall2020_LLCatalog.docx')
documentName = "Fall2020_LLCatalog.docx"
documentSemester = "Fall"
documentYear = "2020"

# document = Document('Spring2020_LeisureLearningCatalogFULL.docx')
# documentName = "Spring2020_LeisureLearningCatalogFULL.docx"
# documentSemester = "Spring"
# documentYear = "2020"

示例#11
0
def writeWorksheet(ws: xlsxwriter.worksheet,
                   knowledgeArea: KnowledgeArea) -> None:
    """

        Iterate through the global collection of KnowledgeAreas
        and write them to a worksheet in an Excel workbook.

        :param ws: Excel Worksheet Object
        :param knowledgeArea: KnowledgeArea Object

    """

    global courses
    global learningObjectives

    row = 0
    col = 0

    ws.write(row, col, 'CourseId')
    col += 1

    ws.write(row, col, 'CourseTitle - As Extracted')
    col += 1

    ws.write(row, col, 'learningObjectiveId')
    col += 1

    ws.write(row, col, 'learningObjective - As Extracted')
    col += 1

    ws.write(row, col, 'learningObjective - As Revised')

    row += 1
    col = 0

    knowledgeAreaId = knowledgeArea.getId()

    for course in courses:
        #print("Course {}, {} ".format(course.getTitle(), course.getKnowledgeAreaId()))
        if str(course.getKnowledgeAreaId()) == str(knowledgeAreaId):
            courseId = course.getId()
            if course.getDescription() == "":
                ws.write(row, col, courseId)
                col += 1
                ws.write(row, col, course.getTitle())
                row += 1
                col = 0
                # write another row for the course to allow for 2 learning outcomes
                ws.write(row, col, courseId)
                col += 1
                ws.write(row, col, course.getTitle())
                row += 1
                col = 0
                continue
            else:
                for learningObjective in learningObjectives:
                    #print("LearningObjective: {}, {} ".format(learningObjective.getText(), learningObjective.getCourseId()))

                    if str(learningObjective.getCourseId()) == str(courseId):
                        ws.write(row, col, courseId)
                        col += 1
                        ws.write(row, col, course.getTitle())
                        col += 1
                        ws.write(row, col, learningObjective.getId())
                        col += 1
                        ws.write(row, col, learningObjective.getText())
                        row += 1
                        col = 0
                continue