Skip to content

Commit ad720c8

Browse files
authored
Merge pull request #44 from coreofscience/bibtex-support
Scopus support
2 parents 1d1fb3a + dc7c106 commit ad720c8

File tree

13 files changed

+150
-58
lines changed

13 files changed

+150
-58
lines changed

src/components/tree/Reference.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const Reference: FC<Props> = ({
3434
simple = true,
3535
}: Props) => (
3636
<div className="reference" id={label}>
37-
{!!title && simple && <div className="title">{title}</div>}
3837
{!!authors && (
3938
<Fragment>
4039
<span className="authors">
@@ -50,7 +49,7 @@ const Reference: FC<Props> = ({
5049
{". "}
5150
</Fragment>
5251
)}
53-
{!!title && !simple && (
52+
{!!title && (
5453
<Fragment>
5554
<span className="title">{title}</span>
5655
{". "}

src/components/tree/Tree.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import sortBy from "lodash.sortby";
44
import StarImgage from "../vectors/StarImage";
55

66
import Reference from "./Reference";
7+
import { mostCommon } from "../../utils/arrays";
78
import { Article } from "../../utils/customTypes";
89

910
import "./Tree.css";
10-
import { mostCommon } from "../../utils/isiUtils";
1111

1212
interface Props {
1313
data: { [section: string]: Article[] };

src/components/upload/FileCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { FC } from "react";
33
import CancelFile from "../vectors/CancelFile";
44
import MoveFirstIcon from "../vectors/MoveFirstIcon";
55

6-
import { round } from "../../utils/mathUtils";
6+
import { round } from "../../utils/math";
77
import { MAX_SIZE } from "../../utils/computeQuantities";
88

99
import "./FileCard.css";

src/components/upload/FileDropper.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React, { FC, useCallback } from "react";
22
import { useDropzone } from "react-dropzone";
33
import "./FileDropper.css";
44

5-
import { looksLikeIsi } from "../../utils/isiUtils";
5+
import { looksLikeIsi } from "../../utils/isi";
6+
import { looksLikeScopus } from "../../utils/scopus";
67
import useUpload from "../../hooks/useUpload";
78
import useError from "../../hooks/useError";
89

@@ -27,7 +28,7 @@ const FileDropper: FC<Props> = () => {
2728
.map((file) => file.text().then((text) => ({ text, file })))
2829
).then((data) => {
2930
data.forEach(({ text, file }) => {
30-
if (looksLikeIsi(text)) {
31+
if (looksLikeIsi(text) || looksLikeScopus(text)) {
3132
upload(Object(file).name, file);
3233
} else {
3334
error(Object(file).name, file, FileErrorMap.isi);

src/components/upload/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import useFiles from "../../hooks/useFiles";
1111
import FirebaseContext from "../../context/FirebaseContext";
1212

1313
import computeQuantities, { MAX_SIZE } from "../../utils/computeQuantities";
14-
import { round } from "../../utils/mathUtils";
14+
import { round } from "../../utils/math";
1515

1616
import "./Home.css";
1717

src/components/upload/UploadIndicator.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { FC, useContext, useEffect, useState } from "react";
2-
import "./UploadIndicator.css";
32

43
import FileCard from "./FileCard";
54
import FileContext from "../../context/FileContext";
65
import useFiles from "../../hooks/useFiles";
76
import { MAX_SIZE } from "../../utils/computeQuantities";
87

8+
import "./UploadIndicator.css";
9+
910
interface Props {}
1011

1112
const UploadIndicator: FC<Props> = () => {

src/hooks/useUpload.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
1-
import md5 from "md5";
21
import { useCallback, useContext } from "react";
32

43
import FirebaseContext from "../context/FirebaseContext";
54
import FileContext from "../context/FileContext";
6-
import {
7-
countArticles,
8-
countReferences,
9-
mostCommonKeywords,
10-
} from "../utils/isiUtils";
5+
import metadata from "../utils/metadata";
116

127
const useUpload = () => {
138
const { add, track } = useContext(FileContext);
149
const firebase = useContext(FirebaseContext);
1510

1611
const upload = useCallback(
1712
(name: string, blob: Blob) => {
18-
blob.text().then((text) => {
13+
metadata(name, blob).then((meta) => {
1914
if (firebase === null) return;
20-
const hash = md5(text);
21-
const metadata = {
22-
name,
23-
blob,
24-
hash,
25-
keywords: mostCommonKeywords(text, 3),
26-
articles: countArticles(text),
27-
citations: countReferences(text),
28-
valid: true,
29-
};
30-
add(metadata);
31-
const ref = firebase.storage().ref(`isi-files/${hash}`);
15+
add(meta);
16+
const ref = firebase.storage().ref(`isi-files/${meta.hash}`);
3217

3318
ref
3419
.getDownloadURL()
3520
.then(() => {
36-
track(hash, 100);
21+
track(meta.hash, 100);
3722
})
3823
.catch(() => {
3924
const task = ref.put(blob);
@@ -42,11 +27,11 @@ const useUpload = () => {
4227
(snapshot) => {
4328
const percent =
4429
(snapshot.bytesTransferred / snapshot.totalBytes) * 100;
45-
track(hash, percent);
30+
track(meta.hash, percent);
4631
},
4732
(error) => console.log,
4833
() => {
49-
track(hash, 100);
34+
track(meta.hash, 100);
5035
}
5136
);
5237
});

src/utils/arrays.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const mostCommon = (keywordsList: string[], max: number): string[] => {
2+
let count: { [keyword: string]: number } = {};
3+
for (let keyword of keywordsList) {
4+
count[keyword] = (count[keyword] ? count[keyword] : 0) + 1;
5+
}
6+
const sortCount = Object.entries(count).sort((first, second) =>
7+
first[1] < second[1] ? 1 : -1
8+
);
9+
return sortCount.slice(0, max).map((item) => item[0]);
10+
};
11+
12+
export { mostCommon };

src/utils/customTypes.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ export interface Article {
3434
issue?: string | null;
3535
page?: string | null;
3636
doi?: string | null;
37-
simple?: boolean;
3837
}

src/utils/isiUtils.tsx renamed to src/utils/isi.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const looksLikeIsi = (content: string): boolean => {
1313
return true;
1414
};
1515

16-
const getKeywordsList = (text: string) => {
16+
const keywords = (text: string): string[] => {
1717
const identifier = "ID ";
1818
const keywordsLines = text
1919
.split("\n")
@@ -30,28 +30,12 @@ const getKeywordsList = (text: string) => {
3030
.flat();
3131
};
3232

33-
function mostCommon(keywordsList: string[], max: number) {
34-
let count: { [keyword: string]: number } = {};
35-
for (let keyword of keywordsList) {
36-
count[keyword] = (count[keyword] ? count[keyword] : 0) + 1;
37-
}
38-
const sortCount = Object.entries(count).sort((first, second) =>
39-
first[1] < second[1] ? 1 : -1
40-
);
41-
return sortCount.slice(0, max).map((item) => item[0]);
42-
}
43-
44-
const mostCommonKeywords = (text: string, max: number = 3) => {
45-
const keywordsList = getKeywordsList(text);
46-
return mostCommon(keywordsList, max);
47-
};
48-
49-
const countArticles = (text: string) => {
33+
const countArticles = (text: string): number => {
5034
const identifier = "PT ";
5135
return text.split("\n").filter((line) => line.startsWith(identifier)).length;
5236
};
5337

54-
const countReferences = (text: string) => {
38+
const countReferences = (text: string): number => {
5539
const identifier = "NR ";
5640
return text
5741
.split("\n")
@@ -60,11 +44,4 @@ const countReferences = (text: string) => {
6044
.reduce((n, m) => n + m, 0);
6145
};
6246

63-
export {
64-
ISI_PATTERN,
65-
looksLikeIsi,
66-
mostCommonKeywords,
67-
mostCommon,
68-
countArticles,
69-
countReferences,
70-
};
47+
export { ISI_PATTERN, looksLikeIsi, keywords, countArticles, countReferences };

0 commit comments

Comments
 (0)