Skip to content

Commit

Permalink
Merge pull request #147 from lcnetdev/marc-subject-cyak
Browse files Browse the repository at this point in the history
Marc subject cyak
  • Loading branch information
f-osorio authored Dec 3, 2024
2 parents 2984ec0 + d589e3a commit 4ca6219
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 27 deletions.
24 changes: 13 additions & 11 deletions src/components/panels/edit/fields/LookupComplex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,12 @@ export default {
this.marcDeliminatedLCSHMode = true
//Get the type of search
let selection = document.getElementById(this.guid)
let selected = selection.options[selection.selectedIndex].value
this.searchType = selected
this.marcDeliminatedLCSHModeResults = await utilsNetwork.subjectLinkModeResolveLCSH(this.searchValue)
this.marcDeliminatedLCSHModeResults = await utilsNetwork.subjectLinkModeResolveLCSH(this.searchValue, this.searchType)
this.marcDeliminatedLCSHModeSearching = false
let sendResults = []
if (this.marcDeliminatedLCSHModeResults.resultType != 'ERROR'){
Expand Down Expand Up @@ -659,23 +663,21 @@ export default {
}else{
// we're opening the subject builder, turn this off
this.marcDeliminatedLCSHMode = false
this.marcDeliminatedLCSHModeSearching = false
this.marcDeliminatedLCSHModeTimeout = null
this.marcDeliminatedLCSHModeResults = []
this.authorityLookup = this.searchValue.trim()
this.searchValue = this.searchValue.trim()
// we're opening the subject builder, turn this off
this.marcDeliminatedLCSHMode = false
this.marcDeliminatedLCSHModeSearching = false
this.marcDeliminatedLCSHModeTimeout = null
this.marcDeliminatedLCSHModeResults = []
this.authorityLookup = this.searchValue.trim()
this.searchValue = this.searchValue.trim()
let selection = document.getElementById(this.guid)
let selected = selection.options[selection.selectedIndex].value
this.searchType = selected
this.displaySubjectModal=true
this.$nextTick(() => {
this.$refs.subjectEditorModal.focusInput()
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/panels/edit/modals/SubjectEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,8 @@ updated: function() {
// preselect the search type, if a children's subject
if (this.searchType.includes("Childrens")){
this.searchMode = "CHILD"
} else {
this.searchMode = "LCSHNAF"
}
// this was opened from an existing subject
let profileData = this.profileData
Expand Down
92 changes: 77 additions & 15 deletions src/lib/utils_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const utilsNetwork = {
"controllerHierarchicalGeographicLCSH": new AbortController(),
"controllerGeographicLCSH": new AbortController(),
"controllerGeographicLCNAF": new AbortController(),
"controllerCyak": new AbortController(),
},
subjectSearchActive: false,

Expand Down Expand Up @@ -1250,7 +1251,7 @@ const utilsNetwork = {
* @return {subjectLinkModeResolveLCSHResult} - A {@link subjectLinkModeResolveLCSHResult} result
*/

subjectLinkModeResolveLCSH: async function(lcsh){
subjectLinkModeResolveLCSH: async function(lcsh, searchType=null){
if (this.subjectSearchActive){
for (let controller in this.controllers){
this.controllers[controller].abort()
Expand Down Expand Up @@ -1421,6 +1422,7 @@ const utilsNetwork = {
searchValue: complexHeading
}


for (let heading of headings){

let foundHeading = false
Expand Down Expand Up @@ -1454,6 +1456,10 @@ const utilsNetwork = {
let subjectUrlGeographicLCSH = useConfigStore().lookupConfig['http://id.loc.gov/authorities/subjects'].modes[0]['LCSH All'].url.replace('<QUERY>',searchVal).replace('&count=25','&count=5').replace("<OFFSET>", "1")+'&rdftype=Geographic&memberOf=http://id.loc.gov/authorities/subjects/collection_Subdivisions'
let subjectUrlGeographicLCNAF = useConfigStore().lookupConfig['http://preprod.id.loc.gov/authorities/names'].modes[0]['NAF All'].url.replace('<QUERY>',searchVal).replace('&count=25','&count=5').replace("<OFFSET>", "1")+'&rdftype=Geographic&memberOf=http://id.loc.gov/authorities/subjects/collection_Subdivisions'

let subjectChildren = useConfigStore().lookupConfig['http://id.loc.gov/authorities/childrensSubjects'].modes[0]['LCSHAC All'].url.replace('<QUERY>',searchVal).replace('&count=25','&count=5').replace("<OFFSET>", "1")
let childrenSubjectSubdivision = useConfigStore().lookupConfig['http://id.loc.gov/authorities/childrensSubjects'].modes[0]['LCSHAC All'].url.replace('<QUERY>',searchVal).replace('&count=25','&count=4').replace("<OFFSET>", "1")+'&memberOf=http://id.loc.gov/authorities/subjects/collection_Subdivisions'


searchVal = decodeURIComponent(searchVal)

// console.log('subjectUrlSimpleSubdivison',subjectUrlSimpleSubdivison)
Expand Down Expand Up @@ -1536,6 +1542,20 @@ const utilsNetwork = {
signal: this.controllers.controllerHubsAnchored.signal
}

let searchPayloadChildren = {
processor: 'lcAuthorities',
url: [subjectChildren],
searchValue: searchVal,
signal: this.controllers.controllerCyak.signal
}

let searchPayloadChildrenSub = {
processor: 'lcAuthorities',
url: [childrenSubjectSubdivision],
searchValue: searchVal,
signal: this.controllers.controllerCyak.signal
}

let resultsNames =[]
let resultsNamesSubdivision =[]

Expand All @@ -1552,14 +1572,17 @@ const utilsNetwork = {
let resultsGeographicLCNAF =[]
let resultsGeographicLCSH =[]

let resultsChildren = []
let resultsChildrenSubDiv = []


let resultsGenre=[]


// if it is a primary heading then we need to search LCNAF, HUBS, WORKS, and simple subjects, and do the whole thing with complex subjects
if (heading.primary){
// resultsNames = await this.searchComplex(searchPayloadNames)
[resultsNames, resultsNamesSubdivision, resultsSubjectsSimple, resultsPayloadSubjectsSimpleSubdivision, resultsSubjectsComplex, resultsHierarchicalGeographic,resultsHierarchicalGeographicLCSH, resultsWorksAnchored, resultsHubsAnchored] = await Promise.all([
[resultsNames, resultsNamesSubdivision, resultsSubjectsSimple, resultsPayloadSubjectsSimpleSubdivision, resultsSubjectsComplex, resultsHierarchicalGeographic,resultsHierarchicalGeographicLCSH, resultsWorksAnchored, resultsHubsAnchored, resultsChildren, resultsChildrenSubDiv] = await Promise.all([
this.searchComplex(searchPayloadNames),
this.searchComplex(searchPayloadNamesSubdivision),
this.searchComplex(searchPayloadSubjectsSimple),
Expand All @@ -1568,7 +1591,9 @@ const utilsNetwork = {
this.searchComplex(searchPayloadHierarchicalGeographic),
this.searchComplex(searchPayloadHierarchicalGeographicLCSH),
this.searchComplex(searchPayloadWorksAnchored),
this.searchComplex(searchPayloadHubsAnchored)
this.searchComplex(searchPayloadHubsAnchored),
this.searchComplex(searchPayloadChildren),
this.searchComplex(searchPayloadChildrenSub),
]);

// console.log("searchPayloadSubjectsSimpleSubdivision",searchPayloadSubjectsSimpleSubdivision)
Expand All @@ -1584,6 +1609,8 @@ const utilsNetwork = {
resultsWorksAnchored = resultsWorksAnchored.filter((r)=>{ return (!r.literal) })
resultsHubsAnchored = resultsHubsAnchored.filter((r)=>{ return (!r.literal) })
resultsPayloadSubjectsSimpleSubdivision = resultsPayloadSubjectsSimpleSubdivision.filter((r)=>{ return (!r.literal) })
resultsChildren = resultsChildren.filter((r)=>{ return (!r.literal) })
resultsChildrenSubDiv = resultsChildrenSubDiv.filter((r)=>{ return (!r.literal) })

// console.log("Yeeth")
// console.log("resultsNames",resultsNames)
Expand Down Expand Up @@ -1635,20 +1662,38 @@ const utilsNetwork = {

// console.log("resultsSubjectsSimple",resultsSubjectsSimple)

// if not see if we matched a simple subject that is not a subdivison
if (resultsSubjectsSimple.length>0){
for (let r of resultsSubjectsSimple){
// lower case, remove end space, make double whitespace into one and remove any punctuation
if (heading.label.toLowerCase().trim().replace(/\s+/g,' ').replace(/[\p{P}$+<=>^`|~]/gu, '') == r.label.toLowerCase().trim().replace(/[\p{P}$+<=>^`|~]/gu, '') || heading.label.toLowerCase().trim().replace(/\s+/g,' ').replace(/[\p{P}$+<=>^`|~]/gu, '') == r.vlabel.toLowerCase().trim().replace(/[\p{P}$+<=>^`|~]/gu, '')){
result.resultType = 'PRECOORD-LCSH'
if (!result.hit){ result.hit = [] }
r.heading = heading
result.hit.push(r)
foundHeading = true
break
// see if there is a match for CYAK
if (searchType.includes(":Topic:Childrens:")){
if (resultsChildren.length>0){
for (let r of resultsChildren){
// lower case, remove end space, make double whitespace into one and remove any punctuation
if (heading.label.toLowerCase().trim().replace(/\s+/g,' ').replace(/[\p{P}$+<=>^`|~]/gu, '') == r.label.toLowerCase().trim().replace(/[\p{P}$+<=>^`|~]/gu, '') || heading.label.toLowerCase().trim().replace(/\s+/g,' ').replace(/[\p{P}$+<=>^`|~]/gu, '') == r.vlabel.toLowerCase().trim().replace(/[\p{P}$+<=>^`|~]/gu, '')){
result.resultType = 'PRECOORD-LCSH'
if (!result.hit){ result.hit = [] }
r.heading = heading
result.hit.push(r)
foundHeading = true
break
}
}
if (foundHeading){ continue }
}
} else {
// if not see if we matched a simple subject that is not a subdivison
if (resultsSubjectsSimple.length>0){
for (let r of resultsSubjectsSimple){
// lower case, remove end space, make double whitespace into one and remove any punctuation
if (heading.label.toLowerCase().trim().replace(/\s+/g,' ').replace(/[\p{P}$+<=>^`|~]/gu, '') == r.label.toLowerCase().trim().replace(/[\p{P}$+<=>^`|~]/gu, '') || heading.label.toLowerCase().trim().replace(/\s+/g,' ').replace(/[\p{P}$+<=>^`|~]/gu, '') == r.vlabel.toLowerCase().trim().replace(/[\p{P}$+<=>^`|~]/gu, '')){
result.resultType = 'PRECOORD-LCSH'
if (!result.hit){ result.hit = [] }
r.heading = heading
result.hit.push(r)
foundHeading = true
break
}
}
if (foundHeading){ continue }
}
if (foundHeading){ continue }
}

// see if we matched a LCNAF name as primary compontant
Expand Down Expand Up @@ -1830,6 +1875,22 @@ const utilsNetwork = {
if (foundHeading){ continue }
}

//CYAK subdivisions
if (resultsChildrenSubDiv.length>0 && searchType.includes(":Topic:Childrens:")){
for (let r of resultsChildrenSubDiv){
// lower case, remove end space, make double whitespace into one and remove any punctuation
if (heading.label.toLowerCase().trim().replace(/\s+/g,' ').replace(/[\p{P}$+<=>^`|~]/gu, '') == r.label.toLowerCase().trim().replace(/[\p{P}$+<=>^`|~]/gu, '')){
r.heading = heading
result.hit.push(r)


foundHeading = true
}
}
if (foundHeading){ continue }
}


if (!foundHeading){
// wasn't found, we need to make it a literal
result.hit.push( {
Expand Down Expand Up @@ -1958,6 +2019,7 @@ const utilsNetwork = {
// console.log("result",result)

this.subjectSearchActive = false

return result
},

Expand Down
2 changes: 1 addition & 1 deletion src/stores/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const useConfigStore = defineStore('config', {

versionMajor: 0,
versionMinor: 16,
versionPatch: 23,
versionPatch: 24,

regionUrls: {

Expand Down

0 comments on commit 4ca6219

Please sign in to comment.