Skip to content

Commit 38c0401

Browse files
authored
Merge pull request #738 from lcnetdev/sor-split-and
Improve SOR splitting regex for `and`
2 parents 34852e1 + a4ff262 commit 38c0401

2 files changed

Lines changed: 151 additions & 17 deletions

File tree

src/components/panels/edit/modals/NacoStubCreateModal.vue

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,23 +1585,7 @@
15851585
}
15861586
}
15871587
1588-
// /\s{1};\s{1}|,\s*(?=[^)^\]]*(?:\(|\[|$))|\&|and|und/g) --> split on <space>;<space> and commas not in ()
1589-
// favor splitting on semicolon. Seems reliable to get the first name without bleed from other names. But after that, anything can happen
1590-
if (this.statementOfResponsibility && this.statementOfResponsibility.split(/,?\s+and|und|\&\s+|\s+e\s+|;/g).length>1){
1591-
this.statementOfResponsibilityOptions = this.statementOfResponsibility.split(/,?\s+and|und|\&\s+|\s+e\s+|;/g)
1592-
} else if (this.statementOfResponsibility && this.statementOfResponsibility.split(/,?\s+and|und|\&\s+|,/g).length>1){
1593-
this.statementOfResponsibilityOptions = this.statementOfResponsibility.split(/,?\s+and|und|\&\s+|,/g)
1594-
}
1595-
1596-
// SOR examples that make rules difficult
1597-
// Cecilia Leibovitz ; photographs by David Lewis Taylor & Talia Marek
1598-
// Ana Rodriguez Alvarez, Jeffrey J. Mora Sanchez (directores) ; prologo E. Raul Zaffaroni; prologo a la edicion costarricense Javier Llobet Rodriguez
1599-
// Sally Friedman and Davy Schultz, Editors
1600-
// Pedro Romaguera Esteva ; pròleg, Dr. Jordi Maíz Chacón, Professor de la UIB
1601-
// Dina de Sousa e Santos (organizadora) ; prefácios, Professor Phillip Rothwell (Universidade de Oxford), Doutora Elisabete Vera Cruz (Universidade Agostinho Neto, UAN)
1602-
// Archie Bogle and Don McKay ; compiled by by Gordon Andreassend, Andrew Blackman and Don McKay
1603-
// editor-in-chief, Elaine Wyllie ; associate editors, Barry E. Gidal, Ahsan Moosa Naduvil Valappil, Howard P. Goodkin, Elaine Wirrell, Stephan Schuele
1604-
// Alberto Pitta ; organização, Thais Darzé, Paulo Darzé ; curadoria e texto, Daniel Rangel
1588+
this.statementOfResponsibilityOptions = this.splitSor(this.statementOfResponsibility)
16051589
16061590
let addingDefaultExtraMarcStatements = false
16071591
@@ -1771,6 +1755,35 @@
17711755
17721756
},
17731757
1758+
splitSor: function(sor){
1759+
let split = []
1760+
// /\s{1};\s{1}|,\s*(?=[^)^\]]*(?:\(|\[|$))|\&|and|und/g) --> split on <space>;<space> and commas not in ()
1761+
// favor splitting on semicolon. Seems reliable to get the first name without bleed from other names. But after that, anything can happen
1762+
// \s{1};\s{1}|;\s*(?=[^)^\]]*(?:\(|\[|$))|\&|and|und
1763+
// ;\s+and|und|\&\s+|\s+e\s+|;\s+
1764+
// ;|;\s?(?=(and))|(?<=;)\s?and
1765+
// ;|;\s?(?=and)
1766+
if (sor && sor.split(/(?:;?\s?(?:and|und|\&))\s?(?<=;.*)|\s?;\s?/g).length>1){
1767+
split = sor.split(/(?:;?\s?(?:and|und|\&))\s?(?<=;.*)|\s?;\s?/g)
1768+
} else if (sor && sor.split(/(?:,?\s?(?:and|und|\&))\s?(?<=,.*)|\s?,\s?/g).length>1){
1769+
split = sor.split(/(?:,?\s?(?:and|und|\&))\s?(?<=,.*)|\s?,\s?/g)
1770+
} else if (sor && sor.split(/\s+(?:and|und|\&){1}\s+/g).length>1){
1771+
split = sor.split(/\s+(?:and|und|\&){1}\s+/g)
1772+
}
1773+
1774+
return split //.map((name) => name.trim())
1775+
1776+
// SOR examples that make rules difficult
1777+
// Cecilia Leibovitz ; photographs by David Lewis Taylor & Talia Marek
1778+
// Ana Rodriguez Alvarez, Jeffrey J. Mora Sanchez (directores) ; prologo E. Raul Zaffaroni; prologo a la edicion costarricense Javier Llobet Rodriguez
1779+
// Sally Friedman and Davy Schultz, Editors
1780+
// Pedro Romaguera Esteva ; pròleg, Dr. Jordi Maíz Chacón, Professor de la UIB
1781+
// Dina de Sousa e Santos (organizadora) ; prefácios, Professor Phillip Rothwell (Universidade de Oxford), Doutora Elisabete Vera Cruz (Universidade Agostinho Neto, UAN)
1782+
// Archie Bogle and Don McKay ; compiled by by Gordon Andreassend, Andrew Blackman and Don McKay
1783+
// editor-in-chief, Elaine Wyllie ; associate editors, Barry E. Gidal, Ahsan Moosa Naduvil Valappil, Howard P. Goodkin, Elaine Wirrell, Stephan Schuele
1784+
// Alberto Pitta ; organização, Thais Darzé, Paulo Darzé ; curadoria e texto, Daniel Rangel
1785+
},
1786+
17741787
update670: function(){
17751788
17761789
if (this.preferenceStore.returnValue('--b-edit-complex-nar-advanced-mode')){
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { expect, test } from 'vitest'
2+
import { shallowMount } from '@vue/test-utils'
3+
import NacoStubCreateModal from '@/components/panels/edit/modals/NacoStubCreateModal.vue'
4+
5+
6+
const sorSemi = 'Timothy R. Amidon; Ehren Helmut Pflugfelder; Daniel P. Richards; Donnie Johnson Sackey'
7+
const sorSpaceSemi = 'Timothy R. Amidon ; Ehren Helmut Pflugfelder ; Daniel P. Richards ; Donnie Johnson Sackey'
8+
const sorSpaceMixedSemi = 'Timothy R. Amidon ; Ehren Helmut Pflugfelder; Daniel P. Richards ; Donnie Johnson Sackey'
9+
const sorSemiAnd = 'Timothy R. Amidon; Ehren Helmut Pflugfelder; Daniel P. Richards and Donnie Johnson Sackey'
10+
const sorSemisAnd = 'Timothy R. Amidon; Ehren Helmut Pflugfelder; Daniel P. Richards; and Donnie Johnson Sackey'
11+
12+
const sorSemiAmp = 'Timothy R. Amidon; Ehren Helmut Pflugfelder; Daniel P. Richards & Donnie Johnson Sackey'
13+
const sorSemisAmp = 'Timothy R. Amidon; Ehren Helmut Pflugfelder; Daniel P. Richards; & Donnie Johnson Sackey'
14+
15+
const sorSemiUnd = 'Timothy R. Amidon; Ehren Helmut Pflugfelder; Daniel P. Richards und Donnie Johnson Sackey'
16+
const sorSemisUnd = 'Timothy R. Amidon; Ehren Helmut Pflugfelder; Daniel P. Richards; und Donnie Johnson Sackey'
17+
18+
const sorCommas = 'Timothy R. Amidon, Ehren Helmut Pflugfelder, Daniel P. Richards, Donnie Johnson Sackey'
19+
const sorCommasAnd = 'Timothy R. Amidon, Ehren Helmut Pflugfelder, Daniel P. Richards, and Donnie Johnson Sackey'
20+
const sorCommaAnd = 'Timothy R. Amidon, Ehren Helmut Pflugfelder, Daniel P. Richards and Donnie Johnson Sackey'
21+
22+
const sorCommasUnd = 'Timothy R. Amidon, Ehren Helmut Pflugfelder, Daniel P. Richards, und Donnie Johnson Sackey'
23+
const sorCommasAmp = 'Timothy R. Amidon, Ehren Helmut Pflugfelder, Daniel P. Richards, & Donnie Johnson Sackey'
24+
25+
const sorCommaUnd = 'Timothy R. Amidon, Ehren Helmut Pflugfelder, Daniel P. Richards und Donnie Johnson Sackey'
26+
const sorCommaAmp = 'Timothy R. Amidon, Ehren Helmut Pflugfelder, Daniel P. Richards & Donnie Johnson Sackey'
27+
28+
29+
const sorAnd = 'Timothy R. Amidon and Ehren Helmut Pflugfelder and Daniel P. Richards and Donnie Johnson Sackey'
30+
31+
const resultExpected = ['Timothy R. Amidon', 'Ehren Helmut Pflugfelder', 'Daniel P. Richards', 'Donnie Johnson Sackey']
32+
33+
describe('SOR Splitting', () => {
34+
35+
test('Only Semicolons', async () => {
36+
let split = NacoStubCreateModal.methods.splitSor(sorSemi)
37+
expect(split).toStrictEqual(resultExpected)
38+
});
39+
40+
test('<space> Semicolons', async () => {
41+
let split = NacoStubCreateModal.methods.splitSor(sorSpaceSemi)
42+
expect(split).toStrictEqual(resultExpected)
43+
});
44+
45+
test('Mixed spaced semicolons', async () => {
46+
let split = NacoStubCreateModal.methods.splitSor(sorSpaceMixedSemi)
47+
expect(split).toStrictEqual(resultExpected)
48+
});
49+
50+
test('semicolons with "and"', async () => {
51+
let split = NacoStubCreateModal.methods.splitSor(sorSemiAnd)
52+
expect(split).toStrictEqual(resultExpected)
53+
});
54+
55+
test('semicolons with "; and"', async () => {
56+
let split = NacoStubCreateModal.methods.splitSor(sorSemisAnd)
57+
expect(split).toStrictEqual(resultExpected)
58+
});
59+
60+
test('semicolons with "&"', async () => {
61+
let split = NacoStubCreateModal.methods.splitSor(sorSemiAmp)
62+
expect(split).toStrictEqual(resultExpected)
63+
});
64+
65+
test('semicolons with "; &"', async () => {
66+
let split = NacoStubCreateModal.methods.splitSor(sorSemisAmp)
67+
expect(split).toStrictEqual(resultExpected)
68+
});
69+
70+
test('semicolons with "und"', async () => {
71+
let split = NacoStubCreateModal.methods.splitSor(sorSemiUnd)
72+
expect(split).toStrictEqual(resultExpected)
73+
});
74+
75+
test('semicolons with "; und"', async () => {
76+
let split = NacoStubCreateModal.methods.splitSor(sorSemisUnd)
77+
expect(split).toStrictEqual(resultExpected)
78+
});
79+
80+
test('only commas', async () => {
81+
let split = NacoStubCreateModal.methods.splitSor(sorCommas)
82+
expect(split).toStrictEqual(resultExpected)
83+
});
84+
85+
test('commas with ", and"', async () => {
86+
let split = NacoStubCreateModal.methods.splitSor(sorCommasAnd)
87+
expect(split).toStrictEqual(resultExpected)
88+
});
89+
90+
test('commas with "and"', async () => {
91+
let split = NacoStubCreateModal.methods.splitSor(sorCommaAnd)
92+
expect(split).toStrictEqual(resultExpected)
93+
});
94+
95+
test('commas with "und"', async () => {
96+
let split = NacoStubCreateModal.methods.splitSor(sorCommaUnd)
97+
expect(split).toStrictEqual(resultExpected)
98+
});
99+
100+
test('commas with "&"', async () => {
101+
let split = NacoStubCreateModal.methods.splitSor(sorCommaAmp)
102+
expect(split).toStrictEqual(resultExpected)
103+
});
104+
105+
test('commas with ", und"', async () => {
106+
let split = NacoStubCreateModal.methods.splitSor(sorCommasUnd)
107+
expect(split).toStrictEqual(resultExpected)
108+
});
109+
110+
test('commas with ", &"', async () => {
111+
let split = NacoStubCreateModal.methods.splitSor(sorCommasAmp)
112+
expect(split).toStrictEqual(resultExpected)
113+
});
114+
115+
test('Only "and"', async () => {
116+
let split = NacoStubCreateModal.methods.splitSor(sorAnd)
117+
expect(split).toStrictEqual(resultExpected)
118+
});
119+
120+
121+
})

0 commit comments

Comments
 (0)