func newInsertCollectionsTask(operationHarvest Operationer, repository *repository.Repository) *InsertCollectionsTask { tableName := "repository_collection" columns := "`repository`, `path`, `spec`, `name`" collectionsBuffer := database.NewSQLBuffer(tableName, columns) return &InsertCollectionsTask{ Task: &Task{ operation: operationHarvest, Task: newTask(operationHarvest.GetOperation(), "Insert Formats"), }, collectionsBuffer: collectionsBuffer, repository: repository, } }
func newInsertFormatsTask(operationHarvest Operationer, repository *repository.Repository) *InsertFormatsTask { tableName := "repository_format" columns := "`repository`, `md_schema`, `namespace`, `prefix`" formatsBuffer := database.NewSQLBuffer(tableName, columns) return &InsertFormatsTask{ Task: &Task{ operation: operationHarvest, Task: newTask(operationHarvest.GetOperation(), "Insert Formats"), }, repository: repository, formatsBuffer: formatsBuffer, } }
func newInsertRecordsTask(operationHarvest Operationer, repository *repository.Repository) *InsertRecordsTask { var createKeysBuffer = func() *database.SQLBuffer { columns := "`resource_key`, `repository`, `value`, `resource`" tableName := "resource_key" return database.NewSQLBuffer(tableName, columns) } var createRepositoryBuffer = func() *database.SQLBuffer { columns := "`repository`, `identifier`, `datestamp`" tableName := "repository_resource" return database.NewSQLBuffer(tableName, columns) } keysBuffer := createKeysBuffer() repositoryBuffer := createRepositoryBuffer() return &InsertRecordsTask{ Task: &Task{ operation: operationHarvest, Task: newTask(operationHarvest.GetOperation(), "Insert Records"), }, repository: repository, keysBuffer: keysBuffer, repositoryBuffer: repositoryBuffer, } }
func newInsertIdentifiersTask(operationHarvest Operationer, repository *repository.Repository) *InsertIdentifiersTask { var createIdentifiersBuffer = func() *database.SQLBuffer { columns := "`identifier`, `value`, `repository`" tableName := "identifier" return database.NewSQLBuffer(tableName, columns) } var createSetsBuffer = func() *database.SQLBuffer { columns := "`identifier`, `set_spec`, `repository`" tableName := "identifier_set" return database.NewSQLBuffer(tableName, columns) } identifiersBuffer := createIdentifiersBuffer() setsBuffer := createSetsBuffer() return &InsertIdentifiersTask{ Task: &Task{ operation: operationHarvest, Task: newTask(operationHarvest.GetOperation(), "Insert Identifiers"), }, repository: repository, identifiersBuffer: identifiersBuffer, setsBuffer: setsBuffer, } }
func (analyser ModuleAnalyser) saveIdentifiers(identifiers []string) { columns := "`analyse`, `resource`, `module`" table := "suggestion_resource" buffer := database.NewSQLBuffer(table, columns) for _, identifier := range identifiers { buffer.AddRow(analyser.parent.parent.id, identifier, analyser.module.GetID()) } err := buffer.Exec() if err != nil { panic(err) } }
func (analyser *InstitutionAnalyser) insertProgramData(programAnalyser ProgramAnalyser) { columns := "`analyse`, `program`, `keywords`, `formats`, `description`" tableName := "digest_program" analyser.programBuffer = database.NewSQLBuffer(tableName, columns) analyser.programBuffer.ChangeLimit(15) d1 := programAnalyser.GetKeywordsDigest() d2 := programAnalyser.GetFormatsDigest() d3 := programAnalyser.GetDescriptionDigest() analyser.programBuffer.AddRow(analyser.parent.id, programAnalyser.GetProgram().GetID(), d1.GetPlainJSON(), d2.GetPlainJSON(), d3.GetPlainJSON()) err := analyser.programBuffer.Exec() if err != nil { fmt.Println(err) } }
func (analyser *InstitutionAnalyser) insertModuleData(InstitutionAnalyser ModuleAnalyser) { columns := "`analyse`, `module`, `keywords`, `formats`, `description`" tableName := "digest_module" analyser.moduleBuffer = database.NewSQLBuffer(tableName, columns) analyser.moduleBuffer.ChangeLimit(30) d1 := InstitutionAnalyser.GetKeywordsDigest() d2 := InstitutionAnalyser.GetFormatsDigest() d3 := InstitutionAnalyser.GetDescriptionDigest() analyser.moduleBuffer.AddRow(analyser.parent.id, InstitutionAnalyser.GetModule().GetID(), d1.GetPlainJSON(), d2.GetPlainJSON(), d3.GetPlainJSON()) err := analyser.moduleBuffer.Exec() if err != nil { fmt.Println(err) } }
func (analyser *InstitutionAnalyser) perform() { institution := analyser.institution subjects := education.GetAllSubjects() for _, subject := range subjects { exists := false programs := institution.GetProgramsBySubjectID(subject.GetID()) keywords := word.NewDigester("") formats := word.NewDigester("") description := word.NewDigester("") for _, program := range programs { exists = true fieldList := "`description`, `formats`, `keywords`" sql := "SELECT " + fieldList + " FROM `digest_program` WHERE program=? AND analyse=? " rows, _ := database.Connection.Query(sql, program.GetID(), analyser.parent.id) for rows.Next() { var s1, s2, s3 string rows.Scan(&s1, &s2, &s3) description = description.Combine(word.NewDigesterFromJSON(s1)) formats = formats.Combine(word.NewDigesterFromJSON(s2)) keywords = keywords.Combine(word.NewDigesterFromJSON(s3)) } } if exists { keywords.SortByCounter("DESC") description.SortByCounter("DESC") formats.SortByCounter("DESC") columns := "`institution`, `subject`, `description`, `formats`, `keywords`, `analyse`" table := "digest_institution" buffer := database.NewSQLBuffer(table, columns) buffer.AddRow(institution.ID, subject.GetID(), description.GetPlainJSON(), formats.GetPlainJSON(), keywords.GetPlainJSON(), analyser.parent.id) err := buffer.Exec() if err != nil { fmt.Println(err) } } } }
// let's start the magic func (analyser SubjectAnalyser) start() { subject := analyser.GetSubject() exists := false institutions := repository.GetAllInstitutions() ownDescription := analyser.getDescription() keywords := word.NewDigester("") formats := word.NewDigester("") description := word.NewDigester("") for _, institution := range institutions { exists = true d1, d2, d3 := analyser.getDigesters(institution) keywords = keywords.Combine(d1) formats = formats.Combine(d2) description = description.Combine(d3) } if exists || len(ownDescription.GetData()) != 0 { description = description.Combine(ownDescription) description.SortByCounter("DESC") formats.SortByCounter("DESC") keywords.SortByCounter("DESC") columns := "`subject`, `description`, `formats`, `keywords`, `analyse`" table := "digest_subject" buffer := database.NewSQLBuffer(table, columns) buffer.AddRow(subject.GetID(), description.GetPlainJSON(), formats.GetPlainJSON(), keywords.GetPlainJSON(), analyser.parent.id) err := buffer.Exec() if err != nil { fmt.Println(err) } } }