import os, json, unicodedata  #import those libraries

# SCRIPT WITH OUR PREVIOUS FUNCTIONS
import functions  #import our functions page

###########################################################
# VARIABLES ###############################################
###########################################################

settings = functions.loadYmlSettings(
    "settings.yml")  #load our settings yaml file

###########################################################
# MINI TEMPLATES ##########################################
###########################################################

connectionsTemplate = """
<button class="collapsible">Similar Texts (<i>tf-idf</i> + cosine similarity)</button>
  <div class="content">
  <ul>
    <li>
    <b>Sim*</b>: <i>cosine similarity</i>; 1 is a complete match, 0 — nothing similar;
    cosine similarity is calculated using <i>tf-idf</i> values of top keywords.</li>
  </ul>
  </div>
<table id="publications" class="mainList">
<thead>
    <tr>
        <th>link</th>
        <th>Sim*</th>
        <th>Author(s), Year, Title, Pages</th>
Exemplo n.º 2
0
# NEW LIBRARIES
import pandas as pd
from sklearn.feature_extraction.text import (CountVectorizer, TfidfTransformer)
from sklearn.metrics.pairwise import cosine_similarity

import os, json, re, random

# SCRIPT WITH OUR PREVIOUS FUNCTIONS
import functions

###########################################################
# VARIABLES ###############################################
###########################################################

settings = functions.loadYmlSettings("settings.yml")

###########################################################
# MAIN FUNCTIONS ##########################################
###########################################################

from wordcloud import WordCloud
import matplotlib.pyplot as plt


def generateWordCloud(citeKey, pathToFile):
    # aggregate dictionary
    data = json.load(open(pathToFile, "r", encoding="UTF8"))
    dataNew = {}
    for page, pageDic in data.items():
        for term, tfIdf in pageDic.items():
            if term in dataNew:
import re, os, yaml, json, random
from datetime import datetime

# SCRIPT WITH OUR PREVIOUS FUNCTIONS
import functions

###########################################################
# VARIABLES ###############################################
###########################################################

settings = functions.loadYmlSettings(
    "Memex_config.yml"
)  #load yaml file and process settings with pre-defined functions

###########################################################
# FUNCTIONS ###############################################
###########################################################


def searchOCRresults(
        pathToMemex,
        searchString):  #function to search Memex for specific keyword(s)
    print("SEARCHING FOR: `%s`" %
          searchString)  #print statement for convenience
    files = functions.dicOfRelevantFiles(
        pathToMemex, ".json"
    )  #use pre-defined function to build a dictionary from all the ocred files
    results = {}  #empty dic

    for citationKey, pathToJSON in files.items(
    ):  #loop through the ocred files individually by citekey
Exemplo n.º 4
0
import functions

###########################################################
# VARIABLES ###############################################
###########################################################

settingsFile = "./settings.yml"
settings = functions.loadYmlSettings(settingsFile)

bibAll = settings["bib_all"]
memexPath = settings["path_to_memex"]

###########################################################
# PROCESS ALL RECORDS #####################################
###########################################################


def processAllRecords(bibData):
    for k, v in bibData.items():
        functions.processBibRecord(memexPath, v)


bibData = functions.loadBib(bibAll)
processAllRecords(bibData)

print("Done!")
import pandas as pd  # import panda library
from sklearn.feature_extraction.text import (
    CountVectorizer, TfidfTransformer
)  #import the features from sklearn helping to transform the data
from sklearn.metrics.pairwise import cosine_similarity  #cosine_similarity feature from the sklearn

import os, yaml, json, re, sys  #import other usual libraries

# SCRIPT WITH OUR PREVIOUS FUNCTIONS
import functions  #import our functions

###########################################################
# VARIABLES ###############################################
###########################################################

settings = functions.loadYmlSettings(
    "settings.yml")  #load our yaml settings file
stopWFile = settings["stopwords"]  #determine our stopwords from settingsfile
stopwordsList = open(stopWFile, "r", encoding="utf8").read().split(
    "\n"
)  ## file with stopwords to get better results #ioends the stppwords, reads and splits
###########################################################
# MAIN FUNCTIONS ##########################################
###########################################################


def filterTfidfDictionary(
        dictionary, threshold, lessOrMore
):  #define a function for the filtering of the tf-idf-dictionary
    dictionaryFilt = {}  #create empy dictionary
    for item1, citeKeyDist in dictionary.items(
    ):  #loop through the outer dictionary which contains the title of each publication
Exemplo n.º 6
0
# NEW LIBRARIES
import pdf2image  # extracts images from PDF
import pytesseract  # interacts with Tesseract, which extracts text from images

import os, yaml, json, random

# SCRIPT WITH OUR PREVIOUS FUNCTIONS
import functions

###########################################################
# VARIABLES ###############################################
###########################################################

settings = functions.loadYmlSettings(
    "settings.yml")  #defines and loads our settings yaml file

###########################################################
# MAIN FUNCTIONS ##########################################
###########################################################


# function OCR a PDF, saving each page as an image and
# saving OCR results into a JSON file
def ocrPublication(citationKey, language, pageLimit):  #defines a function
    # generate and create necessary paths
    publPath = functions.generatePublPath(
        settings["path_to_memex"],
        citationKey)  #generates the path to our PDF file
    pdfFile = os.path.join(publPath, citationKey +
                           ".pdf")  #creates the path to the PDF file
    jsonFile = os.path.join(publPath, citationKey +
Exemplo n.º 7
0
import re, os, yaml, json, random
from datetime import datetime

# SCRIPT WITH OUR PREVIOUS FUNCTIONS
import functions  ## load functions

###########################################################
# VARIABLES ###############################################
###########################################################

settings = functions.loadYmlSettings("settings.yml")  ###define settingsfile

###########################################################
# FUNCTIONS ###############################################
###########################################################


def searchOCRresults(pathToMemex, searchString):
    print("SEARCHING FOR: `%s`" % searchString)
    files = functions.dicOfRelevantFiles(pathToMemex,
                                         ".json")  ##load all jsonfiles
    results = {}  ##create empty dictionary

    for citationKey, pathToJSON in files.items():
        data = json.load(open(
            pathToJSON, "r",
            encoding="UTF8"))  ###changend by adding "r" and encoding="UTF8"
        #print(citationKey)
        count = 0  # set counter

        for pageNumber, pageText in data.items():  ###loop through each json
Exemplo n.º 8
0
# NEW LIBRARIES
import pandas as pd
from sklearn.feature_extraction.text import (CountVectorizer, TfidfTransformer)
from sklearn.metrics.pairwise import cosine_similarity

import os, json, re, sys

# SCRIPT WITH OUR PREVIOUS FUNCTIONS
import functions

###########################################################
# VARIABLES ###############################################
###########################################################

settings = functions.loadYmlSettings(
    "settings.yml")  #load yaml file with important, constant settings

###########################################################
# MAIN FUNCTIONS ##########################################
###########################################################


def filterTfidfDictionary(dictionary, threshold,
                          lessOrMore):  #function with 3 parameters
    dictionaryFilt = {}  #create dictionary
    for item1, citeKeyDist in dictionary.items(
    ):  #loop through dictionary layer 1
        dictionaryFilt[item1] = {}  #dictionary for filtered items
        for item2, value in citeKeyDist.items(
        ):  #loop through dictionary layer 2
            if lessOrMore == "less":  #if condition "less" for threshold value
Exemplo n.º 9
0
import os, json

# SCRIPT WITH OUR PREVIOUS FUNCTIONS
import functions

#############################################################
# VARIABLES #################################################
#############################################################

settings = functions.loadYmlSettings(
    "settings.yml")  # Function loads yaml settings

#############################################################
# FUNCTIONS #################################################
#############################################################


# Generates an interface for the publication
def generatePublicationInterface(
        citeKey, pathToBibFile):  # Function generates the HTML pages.
    # Uses citeKey and pathToBibFile as 2 arguments
    print("=" * 80)
    print(citeKey)

    jsonFile = pathToBibFile.replace(
        ".bib",
        ".json")  # Loads JSON file, gets path by replacing .bib extension
    # with .json extension
    with open(jsonFile) as jsonData:
        ocred = json.load(jsonData)
        pNums = ocred.keys()  # Generates page links