Skip to content

Instantly share code, notes, and snippets.

View tsh-code's full-sized avatar

TSH code sharing tsh-code

View GitHub Profile
@tsh-code
tsh-code / spacy-flask.py
Created March 4, 2024 08:25
spacy flask example
from flask import Flask, request, jsonify
import spacy
app = Flask(__name__)
nlp = spacy.load("en_core_web_sm")
def extract_people(text: str):
entities = nlp(text)
full_names = set()
[
{
"text": "Lisa Turner",
"person": {
"firstName": "lisa",
"lastName": "turner",
"honorific": "",
"presumed_gender": "female"
}
},
@tsh-code
tsh-code / compromise.js
Created March 4, 2024 08:22
compromise example
import nlp from 'compromise'
let doc = nlp(`
Lisa Turner and Mark Davis went to the park together. They enjoyed a picnic and played frisbee under the warm sun. Lisa brought sandwiches, while Mark brought refreshing drinks. They laughed, shared stories, and had a great time in each other's company. As the day unfolded, Lisa Turner and Mark Davis realized how much they cherished these simple moments together.
`)
doc.people().json();
ocr_notebook_map = {
"easyocr": "easyocr.ipynb",
"pytesseract": "pytesseract.ipynb",
"kerasocr": "kerasocr.ipynb",
"paddle": "paddle.ipynb",
"tensorflow": "tensorflow.ipynb"
}
def run_ocr(CONFIG):
if CONFIG.get("skip_ocr_processing", False):
config = {
"directory": "OCR/Invoices1",
"ocr_library": "pytesseract",
"output_file": "results-bc-without.txt",
"statistics_file": "statistics-bc-without.txt",
"apply_cropping": False,
"resize_to_fhd": True,
"deskew_image": True,
"threshold_method": "niblack",
"skip_ocr_processing": False,
<?php
// 1.
$isUserModerator = $user->isType(‘moderator’);
class User {
// . . .
public function isType(string $type): bool
{
<?php
$type = $user->type(‘moderator’);
<?php
class Generator {
public function generateJsonFile(array $data): void;
{
$content = json_encode($data);
header(‘Content-Type: application/json`);
header(‘Content-Disposition: attachment; filename="data.json”`);
ob_start();
<?php
class Generator {
private const JSON_TYPE = ‘application/json’;
private const CSV_TYPE = ‘text/csv’;
private const JSON_EXT = ‘json’;
private const CSV_EXT = ‘csv’;
private function disposition(
string $filename,
<?php
class Generator {
// . . .
public function generate(string $filename, array $data, string $fileType): void {
$content = $this->generateContent($data, $fileType);
$this->disposition($filename, $content, $fileType);
}
}