This repository was archived by the owner on May 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtaxonomyService_test.go
885 lines (807 loc) · 32.2 KB
/
taxonomyService_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
package main
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"strings"
)
func TestSubjectServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := SubjectService{"subjects"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 subject tag",
buildContentRefWithSubjects(1),
buildConceptSuggestionsWithSubjects(1),
},
{"Build concept suggestion from a contentRef with no subject tags",
buildContentRefWithSubjects(0),
buildConceptSuggestionsWithSubjects(0),
},
{"Build concept suggestion from a contentRef with multiple subject tags",
buildContentRefWithSubjects(2),
buildConceptSuggestionsWithSubjects(2),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect", test.name))
}
}
func TestSectionServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := SectionService{"sections"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 section tag",
buildContentRefWithSections(1),
buildConceptSuggestionsWithSections(1),
},
{"Build concept suggestion from a contentRef with no section tags",
buildContentRefWithSections(0),
buildConceptSuggestionsWithSections(0),
},
{"Build concept suggestion from a contentRef with multiple section tags",
buildContentRefWithSections(2),
buildConceptSuggestionsWithSections(2),
},
{"Build concept suggestion from a contentRef with a primary section",
buildContentRefWithPrimarySection("sections", 2),
buildConceptSuggestionsWithPrimarySection("sections", 2),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect", test.name))
}
}
func TestTopicServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := TopicService{"topics"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 topic tag",
buildContentRefWithTopics(1),
buildConceptSuggestionsWithTopics(1),
},
{"Build concept suggestion from a contentRef with no topic tags",
buildContentRefWithTopics(0),
buildConceptSuggestionsWithTopics(0),
},
{"Build concept suggestion from a contentRef with multiple topic tags",
buildContentRefWithTopics(2),
buildConceptSuggestionsWithTopics(2),
},
{"Build concept suggestion from a contentRef with 1 topic tag and a primary theme",
buildContentRefWithTopicsWithPrimaryTheme(1),
buildConceptSuggestionsWithTopicsWithPrimaryTheme(1),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect", test.name))
}
}
func TestLocationServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := LocationService{"gl"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 location tag",
buildContentRefWithLocations(1),
buildConceptSuggestionsWithLocations(1),
},
{"Build concept suggestion from a contentRef with no location tags",
buildContentRefWithLocations(0),
buildConceptSuggestionsWithLocations(0),
},
{"Build concept suggestion from a contentRef with multiple location tags",
buildContentRefWithLocations(2),
buildConceptSuggestionsWithLocations(2),
},
{"Build concept suggestion from a contentRef with 1 location tag and primamry location",
buildContentRefWithLocationsWithPrimaryTheme(1),
buildConceptSuggestionsWithLocationsWithPrimaryTheme(1),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect", test.name))
}
}
func TestGenreServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := GenreService{"genres"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 genre tag",
buildContentRefWithGenres(1),
buildConceptSuggestionsWithGenres(1),
},
{"Build concept suggestion from a contentRef with no genre tags",
buildContentRefWithGenres(0),
buildConceptSuggestionsWithGenres(0),
},
{"Build concept suggestion from a contentRef with multiple genre tags",
buildContentRefWithGenres(2),
buildConceptSuggestionsWithGenres(2),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect", test.name))
}
}
func TestSpecialReportServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := SpecialReportService{"specialReports"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 specialReports tag",
buildContentRefWithSpecialReports(1),
buildConceptSuggestionsWithSpecialReports(1),
},
{"Build concept suggestion from a contentRef with no specialReports tags",
buildContentRefWithSpecialReports(0),
buildConceptSuggestionsWithSpecialReports(0),
},
{"Build concept suggestion from a contentRef with multiple specialReports tags",
buildContentRefWithSpecialReports(2),
buildConceptSuggestionsWithSpecialReports(2),
},
{"Build concept suggestion from a contentRef with specialReports as a primary section",
buildContentRefWithPrimarySection("specialReports", 2),
buildConceptSuggestionsWithPrimarySection("specialReports", 2),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect", test.name))
}
}
func TestAlphavilleSeriesServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := AlphavilleSeriesService{"alphavilleSeries"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 alphavilleSeries tag",
buildContentRefWithAlphavilleSeries(1),
buildConceptSuggestionsWithAlphavilleSeries(1),
},
{"Build concept suggestion from a contentRef with no alphavilleSeries tags",
buildContentRefWithAlphavilleSeries(0),
buildConceptSuggestionsWithAlphavilleSeries(0),
},
{"Build concept suggestion from a contentRef with multiple alphavilleSeries tags",
buildContentRefWithAlphavilleSeries(2),
buildConceptSuggestionsWithAlphavilleSeries(2),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect.", test.name))
}
}
func TestOrganisationsServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := OrganisationService{"on"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 organisation tag",
buildContentRefWithOrganisations(1),
buildConceptSuggestionsWithOrganisations(1),
},
{"Build concept suggestion from a contentRef with no organisation tags",
buildContentRefWithOrganisations(0),
buildConceptSuggestionsWithOrganisations(0),
},
{"Build concept suggestion from a contentRef with multiple organisation tags",
buildContentRefWithOrganisations(2),
buildConceptSuggestionsWithOrganisations(2),
},
{"Build concept suggestion from a contentRef with 1 organisation tag and a primary theme",
buildContentRefWithOrganisationWithPrimaryTheme(1),
buildConceptSuggestionsWithOrganisationsWithPrimaryTheme(1),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect: ACTUAL: %s TEST: %s ", test.name, actualConceptSuggestions, test.suggestions))
}
}
func TestPeopleServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := PeopleService{"PN"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 Person tag",
buildContentRefWithPeople(1),
buildConceptSuggestionsWithPeople(1),
},
{"Build concept suggestion from a contentRef with no Person tags",
buildContentRefWithPeople(0),
buildConceptSuggestionsWithPeople(0),
},
{"Build concept suggestion from a contentRef with multiple Person tags",
buildContentRefWithPeople(2),
buildConceptSuggestionsWithPeople(2),
},
{"Build concept suggestion from a contentRef with a primary theme",
buildContentRefWithPeopleWithPrimaryTheme(2),
buildConceptSuggestionsWithPeopleWithPrimaryTheme(2),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions,
actualConceptSuggestions,
fmt.Sprintf("%s: Actual concept suggestions incorrect: ACTUAL: %s TEST: %s ",
test.name,
actualConceptSuggestions,
test.suggestions))
}
}
func TestAuthorServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := AuthorService{"Authors"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 author tag",
buildContentRefWithAuthor(1),
buildConceptSuggestionsWithAuthor(1),
},
{"Build concept suggestion from a contentRef with no author tags",
buildContentRefWithAuthor(0),
buildConceptSuggestionsWithAuthor(0),
},
{"Build concept suggestion from a contentRef with multiple author tags",
buildContentRefWithAuthor(2),
buildConceptSuggestionsWithAuthor(2),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect.", test.name))
}
}
func TestBrandServiceBuildSuggestions(t *testing.T) {
assert := assert.New(t)
service := BrandService{HandledTaxonomy: "brands"}
tests := []struct {
name string
contentRef ContentRef
suggestions []suggestion
}{
{"Build concept suggestion from a contentRef with 1 brand tag",
buildContentRefWithBrands(1),
buildConceptSuggestionsWithBrands(1),
},
{"Build concept suggestion from a contentRef with no brand tags",
buildContentRefWithBrands(0),
buildConceptSuggestionsWithBrands(0),
},
{"Build concept suggestion from a contentRef with multiple brand tags",
buildContentRefWithBrands(2),
buildConceptSuggestionsWithBrands(2),
},
}
for _, test := range tests {
actualConceptSuggestions := service.buildSuggestions(test.contentRef)
assert.Equal(test.suggestions, actualConceptSuggestions, fmt.Sprintf("%s: Actual concept suggestions incorrect", test.name))
}
}
func buildContentRefWithLocations(locationCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["locations"] = locationCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithLocationsWithPrimaryTheme(locationCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["locations"] = locationCount
return buildContentRef(taxonomyAndCount, false, true)
}
func buildContentRefWithTopics(topicCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["topics"] = topicCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithTopicsWithPrimaryTheme(topicCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["topics"] = topicCount
return buildContentRef(taxonomyAndCount, false, true)
}
func buildContentRefWithSubjects(subjectCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["subjects"] = subjectCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithSections(sectionCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["sections"] = sectionCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithPrimarySection(taxonomyName string, sectionCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount[taxonomyName] = sectionCount
return buildContentRef(taxonomyAndCount, true, false)
}
func buildContentRefWithGenres(genreCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["genres"] = genreCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithBrands(count int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["brands"] = count
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithSpecialReports(specialReportCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["specialReports"] = specialReportCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithAlphavilleSeries(seriesCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["alphavilleSeries"] = seriesCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithOrganisations(organisationCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["organisations"] = organisationCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithOrganisationWithPrimaryTheme(orgCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["organisations"] = orgCount
return buildContentRef(taxonomyAndCount, false, true)
}
func buildContentRefWithPeople(peopleCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["people"] = peopleCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRefWithPeopleWithPrimaryTheme(peopleCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["people"] = peopleCount
return buildContentRef(taxonomyAndCount, false, true)
}
func buildContentRefWithAuthor(authorCount int) ContentRef {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["author"] = authorCount
return buildContentRef(taxonomyAndCount, false, false)
}
func buildContentRef(taxonomyAndCount map[string]int, hasPrimarySection bool, hasPrimaryTheme bool) ContentRef {
metadataTags := []tag{}
var primarySection term
var primaryTheme term
for key, count := range taxonomyAndCount {
if strings.EqualFold("subjects", key) {
for i := 0; i < count; i++ {
subjectTerm := term{CanonicalName: subjectNames[i], Taxonomy: "Subjects", ID: subjectTMEIDs[i]}
metadataTags = append(metadataTags, tag{Term: subjectTerm, TagScore: testScore})
}
}
if strings.EqualFold("sections", key) {
for i := 0; i < count; i++ {
sectionsTerm := term{CanonicalName: sectionNames[i], Taxonomy: "Sections", ID: sectionTMEIDs[i]}
sectionsTag := tag{Term: sectionsTerm, TagScore: testScore}
metadataTags = append(metadataTags, sectionsTag)
}
if hasPrimarySection {
primarySection = term{CanonicalName: sectionNames[0], Taxonomy: "Sections", ID: sectionTMEIDs[0]}
}
}
if strings.EqualFold("topics", key) {
for i := 0; i < count; i++ {
topicTerm := term{CanonicalName: topicNames[i], Taxonomy: "Topics", ID: topicTMEIDs[i]}
topicTag := tag{Term: topicTerm, TagScore: testScore}
metadataTags = append(metadataTags, topicTag)
}
if hasPrimaryTheme {
primaryTheme = term{CanonicalName: topicNames[0], Taxonomy: "Topics", ID: topicTMEIDs[0]}
}
}
if strings.EqualFold("locations", key) {
for i := 0; i < count; i++ {
locationTerm := term{CanonicalName: locationNames[i], Taxonomy: "GL", ID: locationTMEIDs[i]}
locationTag := tag{Term: locationTerm, TagScore: testScore}
metadataTags = append(metadataTags, locationTag)
}
if hasPrimaryTheme {
primaryTheme = term{CanonicalName: locationNames[0], Taxonomy: "GL", ID: locationTMEIDs[0]}
}
}
if strings.EqualFold("genres", key) {
for i := 0; i < count; i++ {
genreTerm := term{CanonicalName: genreNames[i], Taxonomy: "Genres", ID: genreTMEIDs[i]}
metadataTags = append(metadataTags, tag{Term: genreTerm, TagScore: testScore})
}
}
if strings.EqualFold("brands", key) {
for i := 0; i < count; i++ {
brandTerm := term{CanonicalName: brandNames[i], Taxonomy: "Brands", ID: brandTMEIDs[i]}
metadataTags = append(metadataTags, tag{Term: brandTerm, TagScore: testScore})
}
}
if strings.EqualFold("specialReports", key) {
for i := 0; i < count; i++ {
specialReportsTerm := term{CanonicalName: specialReportNames[i], Taxonomy: "SpecialReports", ID: specialReportTMEIDs[i]}
sectionsTag := tag{Term: specialReportsTerm, TagScore: testScore}
metadataTags = append(metadataTags, sectionsTag)
}
if hasPrimarySection {
primarySection = term{CanonicalName: specialReportNames[0], Taxonomy: "SpecialReports", ID: specialReportTMEIDs[0]}
}
}
if strings.EqualFold("alphavilleSeries", key) {
for i := 0; i < count; i++ {
alphavilleSeriesTerm := term{CanonicalName: alphavilleSeriesNames[i], Taxonomy: "AlphavilleSeries", ID: alphavilleSeriesTMEIDs[i]}
alphavilleSeriesTag := tag{Term: alphavilleSeriesTerm, TagScore: testScore}
metadataTags = append(metadataTags, alphavilleSeriesTag)
}
}
if strings.EqualFold("organisations", key) {
for i := 0; i < count; i++ {
organisationTerm := term{CanonicalName: organisationNames[i], Taxonomy: "ON", ID: organisationTMEIDs[i]}
organisationTag := tag{Term: organisationTerm, TagScore: testScore}
metadataTags = append(metadataTags, organisationTag)
}
if hasPrimaryTheme {
primaryTheme = term{CanonicalName: organisationNames[0], Taxonomy: "Organisations", ID: organisationTMEIDs[0]}
}
}
if strings.EqualFold("people", key) {
for i := 0; i < count; i++ {
peopleTerm := term{CanonicalName: peopleNames[i], Taxonomy: "PN", ID: peopleTMEIDs[i]}
peopleTag := tag{Term: peopleTerm, TagScore: testScore}
metadataTags = append(metadataTags, peopleTag)
}
if hasPrimaryTheme {
primaryTheme = term{CanonicalName: peopleNames[0], Taxonomy: "People", ID: peopleTMEIDs[0]}
}
}
if strings.EqualFold("author", key) {
for i := 0; i < count; i++ {
authourTerm := term{CanonicalName: authorNames[i], Taxonomy: "Authors", ID: authorTMEIDs[i]}
authorTag := tag{Term: authourTerm, TagScore: testScore}
metadataTags = append(metadataTags, authorTag)
}
}
}
tagHolder := tags{Tags: metadataTags}
return ContentRef{TagHolder: tagHolder, PrimarySection: primarySection, PrimaryTheme: primaryTheme}
}
func buildConceptSuggestionsWithLocations(locationCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["locations"] = locationCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithLocationsWithPrimaryTheme(locationCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["locations"] = locationCount
return buildConceptSuggestions(taxonomyAndCount, false, true)
}
func buildConceptSuggestionsWithTopics(topicCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["topics"] = topicCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithTopicsWithPrimaryTheme(topicsCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["topics"] = topicsCount
return buildConceptSuggestions(taxonomyAndCount, false, true)
}
func buildConceptSuggestionsWithSections(sectionCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["sections"] = sectionCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithPrimarySection(taxonomyName string, sectionCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount[taxonomyName] = sectionCount
return buildConceptSuggestions(taxonomyAndCount, true, false)
}
func buildConceptSuggestionsWithSubjects(subjectCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["subjects"] = subjectCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithGenres(genreCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["genres"] = genreCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithBrands(count int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["brands"] = count
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithSpecialReports(reportCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["specialReports"] = reportCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithAlphavilleSeries(seriesCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["alphavilleSeries"] = seriesCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithOrganisations(orgsCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["organisations"] = orgsCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithOrganisationsWithPrimaryTheme(orgsCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["organisations"] = orgsCount
return buildConceptSuggestions(taxonomyAndCount, false, true)
}
func buildConceptSuggestionsWithPeople(peopleCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["people"] = peopleCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestionsWithPeopleWithPrimaryTheme(peopleCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["people"] = peopleCount
return buildConceptSuggestions(taxonomyAndCount, false, true)
}
func buildConceptSuggestionsWithAuthor(authorCount int) []suggestion {
taxonomyAndCount := make(map[string]int)
taxonomyAndCount["author"] = authorCount
return buildConceptSuggestions(taxonomyAndCount, false, false)
}
func buildConceptSuggestions(taxonomyAndCount map[string]int, hasPrimarySection bool, hasPrimaryTheme bool) []suggestion {
suggestions := []suggestion{}
relevance := score{ScoringSystem: relevanceURI, Value: 0.65}
confidence := score{ScoringSystem: confidenceURI, Value: 0.93}
metadataProvenance := provenance{Scores: []score{relevance, confidence}}
for key, count := range taxonomyAndCount {
if strings.EqualFold("subjects", key) {
for i := 0; i < count; i++ {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(subjectTMEIDs[i])).String(),
PrefLabel: subjectNames[i],
Predicate: classification,
Types: []string{subjectURI},
}
subjectSuggestion := suggestion{Thing: thing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, subjectSuggestion)
}
}
if strings.EqualFold("sections", key) {
for i := 0; i < count; i++ {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(sectionTMEIDs[i])).String(),
PrefLabel: sectionNames[i],
Predicate: classification,
Types: []string{sectionURI},
}
sectionSuggestion := suggestion{Thing: thing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, sectionSuggestion)
}
if count > 0 && hasPrimarySection {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(sectionTMEIDs[0])).String(),
PrefLabel: sectionNames[0],
Predicate: primaryClassification,
Types: []string{sectionURI},
}
sectionSuggestion := suggestion{Thing: thing}
suggestions = append(suggestions, sectionSuggestion)
}
}
if strings.EqualFold("topics", key) {
for i := 0; i < count; i++ {
oneThing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(topicTMEIDs[i])).String(),
PrefLabel: topicNames[i],
Predicate: conceptMajorMentions,
Types: []string{topicURI},
}
topicSuggestion := suggestion{Thing: oneThing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, topicSuggestion)
}
if count > 0 && hasPrimaryTheme {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(topicTMEIDs[0])).String(),
PrefLabel: topicNames[0],
Predicate: about,
Types: []string{topicURI},
}
topicSuggestion := suggestion{Thing: thing}
suggestions = append(suggestions, topicSuggestion)
}
}
if strings.EqualFold("locations", key) {
for i := 0; i < count; i++ {
oneThing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(locationTMEIDs[i])).String(),
PrefLabel: locationNames[i],
Predicate: conceptMajorMentions,
Types: []string{locationURI},
}
locationSuggestion := suggestion{Thing: oneThing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, locationSuggestion)
}
if count > 0 && hasPrimaryTheme {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(locationTMEIDs[0])).String(),
PrefLabel: locationNames[0],
Predicate: about,
Types: []string{locationURI},
}
locationSuggestion := suggestion{Thing: thing}
suggestions = append(suggestions, locationSuggestion)
}
}
if strings.EqualFold("genres", key) {
for i := 0; i < count; i++ {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(genreTMEIDs[i])).String(),
PrefLabel: genreNames[i],
Predicate: classification,
Types: []string{genreURI},
}
genreSuggestion := suggestion{Thing: thing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, genreSuggestion)
}
}
if strings.EqualFold("brands", key) {
for i := 0; i < count; i++ {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(brandTMEIDs[i])).String(),
PrefLabel: brandNames[i],
Predicate: classification,
Types: []string{brandURI},
}
brandSuggestion := suggestion{Thing: thing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, brandSuggestion)
}
}
if strings.EqualFold("specialReports", key) {
for i := 0; i < count; i++ {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(specialReportTMEIDs[i])).String(),
PrefLabel: specialReportNames[i],
Predicate: classification,
Types: []string{specialReportURI},
}
specialReportSuggestion := suggestion{Thing: thing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, specialReportSuggestion)
}
if count > 0 && hasPrimarySection {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(specialReportTMEIDs[0])).String(),
PrefLabel: specialReportNames[0],
Predicate: primaryClassification,
Types: []string{specialReportURI},
}
specialReportSuggestion := suggestion{Thing: thing}
suggestions = append(suggestions, specialReportSuggestion)
}
}
if strings.EqualFold("alphavilleSeries", key) {
for i := 0; i < count; i++ {
oneThing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(alphavilleSeriesTMEIDs[i])).String(),
PrefLabel: alphavilleSeriesNames[i],
Predicate: classification,
Types: []string{alphavilleSeriesURI},
}
alphavilleSeriesSuggestion := suggestion{Thing: oneThing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, alphavilleSeriesSuggestion)
}
}
if strings.EqualFold("organisations", key) {
for i := 0; i < count; i++ {
oneThing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(organisationTMEIDs[i])).String(),
PrefLabel: organisationNames[i],
Predicate: conceptMajorMentions,
Types: []string{organisationURI},
}
organisationSuggestion := suggestion{Thing: oneThing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, organisationSuggestion)
}
if count > 0 && hasPrimaryTheme {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(organisationTMEIDs[0])).String(),
PrefLabel: organisationNames[0],
Predicate: about,
Types: []string{organisationURI},
}
organisationSuggestion := suggestion{Thing: thing}
suggestions = append(suggestions, organisationSuggestion)
}
}
if strings.EqualFold("people", key) {
for i := 0; i < count; i++ {
oneThing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(peopleTMEIDs[i])).String(),
PrefLabel: peopleNames[i],
Predicate: conceptMajorMentions,
Types: []string{personURI},
}
peopleSuggestion := suggestion{Thing: oneThing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, peopleSuggestion)
}
if count > 0 && hasPrimaryTheme {
thing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(peopleTMEIDs[0])).String(),
PrefLabel: peopleNames[0],
Predicate: about,
Types: []string{personURI},
}
peopleSuggestion := suggestion{Thing: thing}
suggestions = append(suggestions, peopleSuggestion)
}
}
if strings.EqualFold("author", key) {
for i := 0; i < count; i++ {
oneThing := thing{
ID: "http://api.ft.com/things/" + NewNameUUIDFromBytes([]byte(authorTMEIDs[i])).String(),
PrefLabel: authorNames[i],
Predicate: hasAuthor,
Types: []string{authorURI},
}
authorSuggestion := suggestion{Thing: oneThing, Provenance: []provenance{metadataProvenance}}
suggestions = append(suggestions, authorSuggestion)
}
}
}
return suggestions
}
var testScore = tagScore{Confidence: 93, Relevance: 65}
var subjectNames = [...]string{"Mining Industry", "Oil Extraction Subsidies"}
var subjectTMEIDs = [...]string{"Mjk=-U2VjdGlvbnM=", "Nw==-R2VucmVz"}
var sectionNames = [...]string{"Companies", "Emerging Markets"}
var sectionTMEIDs = [...]string{"Nw==-R2Bucm3z", "Nw==-U2VjdGlvbnM="}
var topicNames = [...]string{"Big Data", "BP trial"}
var topicTMEIDs = [...]string{"M2YyN2I0NGEtZGZjMi00MDVjLTlkNjAtNGRlNTNhM2EwYjlm-VG9waWNz", "ZWE3YzNhNmQtNGU4MS00MzE0LWIxZWMtYWQxY2M4Y2ZjZDFk-VG9waWNz"}
var locationNames = [...]string{"New York", "Rio"}
var locationTMEIDs = [...]string{"TmV3IFlvcms=-R0w=", "Umlv-R0w="}
var genreNames = [...]string{"News", "Letter"}
var genreTMEIDs = [...]string{"TmV3cw==-R2VucmVz", "TGV0dGVy-R2VucmVz"}
var brandNames = [...]string{"FT", "Martin Wolf"}
var brandTMEIDs = [...]string{"RlQK-QnJhbmRzCg==", "TWFydGluIFdvbGY=-QnJhbmRzCg=="}
var specialReportNames = [...]string{"Business", "Investment"}
var specialReportTMEIDs = [...]string{"U3BlY2lhbFJlcG9ydHM=-R2Bucm3z", "U3BlY2lhbFJlcG9ydHM=-U2VjdGlvbnM="}
var alphavilleSeriesNames = [...]string{"AV Series 1", "AV Series 2"}
var alphavilleSeriesTMEIDs = [...]string{"series1-AV", "series2-AV"}
var organisationNames = [...]string{"Organisation 1", "Organisation 2"}
var organisationTMEIDs = [...]string{"Organisation-1-TME", "Organisation-2-TME"}
var peopleNames = [...]string{"Person 1", "Person 2"}
var peopleTMEIDs = [...]string{"Person-1-TME", "Person-2-TME"}
var authorNames = [...]string{"Author 1", "Author 2"}
var authorTMEIDs = [...]string{"Author-1-TME", "Author-2-TME"}