Skip to content
Snippets Groups Projects
Commit bd0090d0 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

add support for biblatex to scipaper_cli, update readme, make lenght parameter...

add support for biblatex to scipaper_cli, update readme, make lenght parameter optional when geting document meta json or biblatex entries
parent 4962f535
Branches
No related tags found
No related merge requests found
......@@ -2,9 +2,15 @@
libscipaper is a shared library that allows you to get metadata to scientific papers from various database services.
When queried libscipaper will ask eatch of its backends to the database services to try and fill in information about the requested paper in order of the priority given in scipaper.ini or in the order requested by the user of the User API
When queried libscipaper will ask eatch of its backends to the database services to try and fill in information about the requested paper in order of the priority given in scipaper.ini or in the order requested by the user of the User API.
libscipaper also allows you to get full text as well as pdf files for scientific papers where they are availble.
libscipaper also includes a cli utility, scipaper_cli, which allows you to: get referances to papers as json files or biblatex entries
* Get on publications metadata as a json file or as a biblatex entry
* Bulk Download pdfs of papers based on querys
For questions or comments, as well as help with the usage of the plugin API contact devnull@uvos.xyz
Full documentation is avialable at [here](http://uvos.xyz/kiss/libscipaperdoc)
Full documentation is avialable at [here](https://uvos.xyz/kiss/libscipaperdoc)
\page BUILD build
\page BUILD Build
# Build instructions
......
......@@ -21,13 +21,32 @@
#include <scipaper/scipaper.h>
#include <algorithm>
#include <cassert>
#include <fstream>
#include <types.h>
#include "log.h"
#include "options.h"
static constexpr size_t resultsPerPage = 200;
bool grabPapers(const DocumentMeta* meta, bool dryRun, bool savePdf, bool saveText, const std::filesystem::path& outDir, size_t maxCount)
static void saveBiblatex(const DocumentMeta* meta, const std::filesystem::path& path)
{
char* biblatex = document_meta_get_biblatex(meta, NULL, NULL);
std::ofstream file;
file.open(path, std::ios_base::out);
if(file.is_open())
{
file<<biblatex;
file.close();
}
else
{
Log(Log::WARN)<<"Could not save biblatex to"<<path;
}
free(biblatex);
}
static bool grabPapers(const DocumentMeta* meta, bool dryRun, bool savePdf, bool saveText, bool printOnly, bool biblatex, const std::filesystem::path& outDir, size_t maxCount)
{
Log(Log::INFO)<<"Trying to download "<<maxCount<<" results";
RequestReturn* req = sci_fill_meta(meta, nullptr, std::min(maxCount, resultsPerPage), 0);
......@@ -86,10 +105,35 @@ bool grabPapers(const DocumentMeta* meta, bool dryRun, bool savePdf, bool saveTe
Log(Log::WARN)<<"Could not get text for document "<<jsonpath;
}
Log(Log::DEBUG)<<"saveing meta for "<<jsonpath.c_str();
bool ret = document_meta_save(jsonpath.c_str(), req->documents[i], text);
if(!ret)
Log(Log::WARN)<<"Could not save document metadata"<<jsonpath;
if(!printOnly)
{
if(!biblatex)
{
Log(Log::DEBUG)<<"saveing meta for "<<jsonpath.c_str();
bool ret = document_meta_save(jsonpath.c_str(), req->documents[i], text);
if(!ret)
Log(Log::WARN)<<"Could not save document metadata"<<jsonpath;
}
else
{
saveBiblatex(req->documents[i], jsonpath);
}
}
else
{
if(!biblatex)
{
char* json = document_meta_get_json(req->documents[i], text, NULL);
std::cout<<json;
free(json);
}
else
{
char* biblatex = document_meta_get_biblatex(req->documents[i], NULL, NULL);
std::cout<<biblatex;
free(biblatex);
}
}
}
else
{
......@@ -168,7 +212,7 @@ int main(int argc, char** argv)
char* json = document_meta_get_json(&queryMeta, nullptr, &length);
Log(Log::DEBUG)<<"Using document meta: "<<json;
free(json);
ret = grabPapers(&queryMeta, config.dryRun, config.savePdf, config.fullText, config.outDir, config.maxNumber);
ret = grabPapers(&queryMeta, config.dryRun, config.savePdf, config.fullText, config.print, config.biblatex, config.outDir, config.maxNumber);
if(!ret)
return 1;
return 0;
......
......@@ -33,19 +33,21 @@ static char args_doc[] = "";
static struct argp_option options[] =
{
{"verbose", 'v', 0, 0, "Show debug messages" },
{"question", 'q', "[FILE]", 0, "Question you wan the system to awnser" },
{"quiet", 'q', 0, 0, "Show only errors"},
{"key-words", 'k', "[FILE]", 0, "Search in key words" },
{"title", 't', "[STRING]",0, "Search in title"},
{"jornal", 'j', "[STRING]",0, "Search in journal"},
{"abstract", 'a', "[STRING]",0, "Search in abstract"},
{"text", 'e', "[STRING]",0, "Freeform text search"},
{"doi", 'i', "[STRING]",0, "Search for a specific doi" },
{"dry-run", 'd', 0, 0, "Just show how manny results there are"},
{"dry-run", 'd', 0, 0, "Just show how many results there are"},
{"out-dir", 'o', "[DIRECTORY]", 0, "Place to save output" },
{"limit", 'l', "[NUMBER]", 0, "Maximum number of results to process" },
{"pdf", 'p', 0, 0, "Save pdf"},
{"full-text", 'f', 0, 0, "Save full text"},
{"backend", 'b', "[STRING]", 0, "Ask scipaper to use a specific backend"},
{"biblatex", 'x', 0, 0, "metadata in biblatex format"},
{"print", 'r', 0, 0, "print metadata only, dont save anything"},
{ 0 }
};
......@@ -56,7 +58,6 @@ struct Config
std::string journal;
std::string abstract;
std::string text;
std::string question;
std::string doi;
std::string backend;
std::filesystem::path outDir = "./out";
......@@ -64,6 +65,8 @@ struct Config
bool dryRun = false;
bool fullText = false;
bool savePdf = false;
bool biblatex = false;
bool print = false;
};
static error_t parse_opt (int key, char *arg, struct argp_state *state)
......@@ -76,7 +79,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
Log::level = Log::DEBUG;
break;
case 'q':
config->question.assign(arg);
Log::level = Log::ERROR;
break;
case 'k':
config->keywords.assign(arg);
......@@ -114,6 +117,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
case 'p':
config->savePdf = true;
break;
case 'x':
config->biblatex = true;
break;
case 'r':
config->print = true;
break;
default:
return ARGP_ERR_UNKNOWN;
}
......
......@@ -174,7 +174,8 @@ void document_meta_combine(DocumentMeta* target, const DocumentMeta* source)
char* document_meta_get_json(const DocumentMeta* meta, const char* fullText, size_t* length)
{
*length = 0;
if(length)
*length = 0;
if(!meta)
return NULL;
......@@ -242,7 +243,8 @@ char* document_meta_get_json(const DocumentMeta* meta, const char* fullText, siz
g_string_append(string, "}\n");
*length = string->len;
if(length)
*length = string->len;
return string->str;
}
......@@ -319,7 +321,10 @@ char* document_meta_load_full_text_from_json_file(const char* jsonFileName)
char* document_meta_get_biblatex(const DocumentMeta* meta, size_t* length, const char* type)
{
if(!type)
type = "Article";
type = "article";
if(length)
*length = 0;
if(!meta->author)
{
......@@ -373,8 +378,10 @@ char* document_meta_get_biblatex(const DocumentMeta* meta, size_t* length, const
if(meta->journal)
g_string_append_printf(string, "\tjournal={%s},\n", meta->journal);
g_string_append_c(string, '}');
g_string_append_c(string, '\n');
*length = string->len;
if(length)
*length = string->len;
char* str = string->str;
g_string_free(string, false);
return str;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment