Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/news agencies #1163

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"filepond-plugin-file-validate-size": "2.2.0",
"filepond-plugin-file-validate-type": "1.2.4",
"flatpickr": "4.6.3",
"impresso-jscommons": "git+https://[email protected]/impresso/impresso-jscommons.git#v1.3.1",
"impresso-jscommons": "git+https://[email protected]/impresso/impresso-jscommons.git#v1.4.1",
"impresso-theme": "git+https://[email protected]/impresso/impresso-theme.git",
"markdown-it": "12.3.2",
"markdown-it-decorate": "1.2.2",
Expand Down
8 changes: 6 additions & 2 deletions src/components/SearchPills.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
{ 'dripicons-pulse': filter.type === 'daterange' },
{ 'dripicons-calendar': filter.type === 'year' },
{ 'dripicons-suitcase': filter.type === 'collection' },
{ 'dripicons-tag': filter.type === 'type' },
{ 'dripicons-tag': filter.type === 'type' },

{ 'dripicons-print': filter.type === 'country' },
{ 'dripicons-shopping-bag': filter.type === 'accessRight' },
{ 'dripicons-store': filter.type === 'partner' },
Expand Down Expand Up @@ -60,7 +61,7 @@
<!-- type:person, type:location, type:newspaper -->
<span
class="label sp-labelled"
v-if="['person', 'location', 'newspaper'].indexOf(filter.type) !== -1"
v-if="['person', 'location', 'newspaper', 'nag'].indexOf(filter.type) !== -1"
v-html="labelByItems({ items: filter.items, max: 2, op: filter.op })"
:class="filter.context"
>
Expand Down Expand Up @@ -540,6 +541,9 @@ export default {
"location": {
"title": "filter by location (experimental)"
},
"nag": {
"title": "filter by News Agency"
},
"collection": {
"title": "filter by collection"
},
Expand Down
9 changes: 1 addition & 8 deletions src/components/TheHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,12 @@
>
<span>{{ $t('label_compare') }}</span>
</b-nav-item>
<b-nav-item
v-if="textReuseEnabled"
:to="getRouteWithSearchQuery({ name: 'text-reuse-cluster-detail' })"
active-class="active"
>
<span>{{ $t('label_text_reuse') }}</span>
</b-nav-item>
<b-nav-item
v-if="textReuseEnabled"
:to="getRouteWithSearchQuery({ name: 'textReuseOverview' }, { p: 1 })"
active-class="active"
>
<span>{{ $t('label_text_reuse_star') }}</span>
<span>{{ $t('label_text_reuse') }}</span>
</b-nav-item>
<b-nav-item
v-if="user"
Expand Down
4 changes: 4 additions & 0 deletions src/components/modules/SearchQuerySummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default {
'topic',
'person',
'location',
'nag',
'language',
'country',
'year',
Expand Down Expand Up @@ -156,6 +157,7 @@ export default {
case 'location':
case 'person':
case 'collection':
case 'nag':
t = item.name
break
case 'newspaper':
Expand Down Expand Up @@ -355,6 +357,7 @@ export default {
"newspaper": "published in",
"person": "mentioning",
"location": "mentioning",
"nag": "gathered by",
"string": "containing",
"title": "where title includes",
"daterange": "published",
Expand Down Expand Up @@ -382,6 +385,7 @@ export default {
"newspaper": "not published in",
"person": "not mentioning",
"location": "not mentioning",
"nag": "not gathered by",
"string": "not containing",
"title": "where title does not include",
"daterange": "not published",
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/SearchResultsListItem.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template lang="html">
<template>
<b-media class="py-3 border-bottom overflow-hidden search-result-list-item">
<div
v-if="isAvailable()"
Expand Down
3 changes: 3 additions & 0 deletions src/components/modules/lists/ItemLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export default {
t = this.item ? this.item.y : this.val
} else if (['type', 'country', 'language'].includes(this.type)) {
t = this.$t(`buckets.${this.type}.${this.item.uid}`)
} else if(this.type === 'nag') {
t = this.item.uid.replace(/^bert-[a-z]+-\d+-/, '').split('_').join(' ');

} else if (typeof this.item.name === 'string' && this.item.name.length) {
t = this.item.name
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ export default {
optionsTitle: 'Day of publication',
optionsDescription: 'Total number of articles per day',
},
nag: {
title: 'News Agency | News Agency | News Agencies',
filtered: 'results are filtered when:',
optionsTitle: 'News Agency',
filterTitle: 'filter by News Agency',
optionsDescription: 'Total number of articles per News Agency',
empty: 'No news agency available',
context: {
include: 'written by',
exclude: '<b>NOT</b> written by',
},
},
type: {
title: 'Article content type | Article content types | Article content types',
optionsTitle: 'Article content type',
Expand Down
1 change: 1 addition & 0 deletions src/logic/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const SupportedFiltersByContext = Object.freeze({
'entity',
'person',
'location',
'nag',
'topicmodel',
'topic-string',
'entity-string',
Expand Down
4 changes: 4 additions & 0 deletions src/models/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default class Entity {
}

static getNameFromUid(uid) {
if (uid.indexOf('bert-') === 0) {
// debugger
return uid.replace(/^bert-[a-z]+-\d+/, '').split('_').join(' ');
}
return uid.replace(/^aida-\d+-\d+-/, '')
.split('_').join(' ')
.replace(/\$([0-9a-z]+)\$/g, (m, c) => decodeURIComponent(`%${c}`));
Expand Down
2 changes: 1 addition & 1 deletion src/models/FilterFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
filter = new FilterRegex(filterData)
}

if (['entity', 'person', 'location'].indexOf(filterData.type) !== -1) {
if (['entity', 'person', 'location', 'nag'].indexOf(filterData.type) !== -1) {
filter = new FilterEntity(filterData)
}

Expand Down
92 changes: 43 additions & 49 deletions src/pages/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,14 @@ import Article from '@/models/Article';
import FacetModel from '@/models/Facet';
import FilterFactory from '@/models/FilterFactory';
import { searchResponseToFacetsExtractor, buildEmptyFacets } from '@/logic/facets';
import { joinFiltersWithItems, SupportedFiltersByContext } from '@/logic/filters';
import { SupportedFiltersByContext } from '@/logic/filters';
import {
searchQueryGetter,
searchQuerySetter,
} from '@/logic/queryParams';
import {
search as searchService,
searchFacets as searchFacetsService,
filtersItems as filtersItemsService,
exporter as exporterService,
collectionsItems as collectionsItemsService,
} from '@/services';
Expand All @@ -231,6 +230,7 @@ const FACET_TYPES_DPFS = [
'person',
'location',
'topic',
'nag',
];

const FACET_TYPES_S = [
Expand Down Expand Up @@ -258,10 +258,15 @@ export default {
searchResults: [],
paginationTotalRows: 0,
/** @type {Facet[]} */
facets: [],
/** @type {Filter[]} */
filtersWithItems: [],
facets: []
}),
props: {

filtersWithItems: {
type: Array,
default: () => [],
},
},
computed: {
searchQuery: {
...searchQueryGetter(),
Expand Down Expand Up @@ -581,63 +586,52 @@ export default {
this.searchResults = data.map(d => new Article(d));
let facets = searchResponseToFacetsExtractor(FACET_TYPES_S)({ info });
// get remaining facets and enriched filters.
const [
namedEntityFacets,
topicFacets,
filtersWithItems,
collectionFacets,
collectionsItemsIndex,
] = await Promise.all([
searchFacetsService.get('person,location', {
query: {
filters,
group_by: groupBy,
},
}),
searchFacetsService.get('topic', {
const namedEntityFacets = await searchFacetsService.get('person,location', {
query: {
filters,
group_by: groupBy,
},
});
const topicFacets = await searchFacetsService.get('topic', {
query: {
filters,
group_by: groupBy,
},
});
const nagFacets = await searchFacetsService.get('nag', {
query: {
filters,
group_by: groupBy,
},
});
facets = facets.concat(namedEntityFacets, topicFacets, nagFacets);
if(this.isLoggedIn) {
const collectionFacets = await searchFacetsService.get('collection', {
query: {
filters,
group_by: groupBy,
},
}),
filtersItemsService.find({
});
facets = facets.concat(collectionFacets);
const collectionsItemsIndex = await collectionsItemsService.find({
query: {
filters: this.searchQueryHash,
item_uids: this.searchResults.map(d => d.uid),
limit: 100,
},
}).then(joinFiltersWithItems),
this.isLoggedIn
? searchFacetsService.get('collection', {
query: {
filters,
group_by: groupBy,
},
})
: [],
this.isLoggedIn
? collectionsItemsService.find({
query: {
item_uids: this.searchResults.map(d => d.uid),
limit: 100,
},
}).then(({ data }) => data.reduce((acc, d) => {
acc[d.itemId] = d;
return acc;
}, {}))
: {},
]);
facets = facets.concat(collectionFacets, namedEntityFacets, topicFacets);
this.filtersWithItems = filtersWithItems;
// TODO sort facets based on the right order
this.facets = facets.map(f => new FacetModel(f));
if (this.isLoggedIn) {
// add collections.
}).then(({ data }) => data.reduce((acc, d) => {
acc[d.itemId] = d;
return acc;
}, {}));
this.searchResults = this.searchResults.map((article) => {
if (collectionsItemsIndex[article.uid]) {
article.collections = collectionsItemsIndex[article.uid].collections;
}
return article;
});
}


this.facets = facets.map(f => new FacetModel(f));
},
immediate: true,
},
Expand Down
7 changes: 5 additions & 2 deletions src/pages/TextReuse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const FacetTypes = [
'language',
'person',
'location',
'nag',
'textReuseClusterSize',
'textReuseClusterLexicalOverlap',
'textReuseClusterDayDelta',
Expand Down Expand Up @@ -194,6 +195,7 @@ export default {
'language',
'person',
'location',
// 'nag'
].includes(type),
)
},
Expand Down Expand Up @@ -344,7 +346,7 @@ export default {
},
loadFacet(type, opts = {}) {
// eslint-disable-next-line
console.debug('[TextReuse] loadFacet', type, 'query', this.searchFacetApiQueryParams.query)
console.debug('[TextReuse] loadFacet fetching \n - type:', type) // '\n - query', this.searchFacetApiQueryParams.query)
searchFacets
.get(type, {
query: {
Expand All @@ -354,7 +356,7 @@ export default {
})
.then(response => {
const facet = this.facets.find(facet => facet.type === type)
console.debug('[TextReuse] loadFacet', response)
console.debug('[TextReuse] loadFacet success \n - type:', type, '\n - ', response)
if (facet) {
facet.numBuckets = response[0].numBuckets
facet.setBuckets(response[0].buckets)
Expand Down Expand Up @@ -384,6 +386,7 @@ export default {
await this.loadFacet('language')
await this.loadFacet('person')
await this.loadFacet('location')
// await this.loadFacet('nag')
},
immediate: true,
deep: false,
Expand Down