>cogtrix v0.3.0

Math & NLP

Math & Calculation

calculate

Evaluate mathematical expressions safely.

Parameters:

ParameterTypeRequiredDescription
expressionstringYesMath expression to evaluate

Supported Functions:

  • Basic operators: +, -, *, /, **, %
  • Built-in: abs, round, min, max, sum
  • Powers & logarithms: sqrt, pow, exp, log, log10, log2
  • Trigonometric: sin, cos, tan, asin, acos, atan, atan2
  • Hyperbolic: sinh, cosh, tanh
  • Angular conversion: degrees, radians
  • Rounding: ceil, floor, trunc
  • Other: factorial, gcd
  • Constants: pi, e, tau, inf

Safety limits: factorial capped at 1,558; exponents capped at magnitude 1,000.

Examples:

sqrt(16) + 2**3        → 12.0
sin(pi/2)              → 1.0
log(100, 10)           → 2.0
factorial(5)           → 120
ceil(3.2)              → 4

Date & Time

get_current_datetime

Get current date and time in any timezone.

Parameters:

ParameterTypeRequiredDescription
timezonestringNoTimezone name (default: UTC)
output_formatstringNoOutput format (default: %Y-%m-%d %H:%M:%S %Z)

Examples:

Timezone: America/New_York
Timezone: Europe/London
Timezone: Asia/Tokyo

convert_timezone

Convert datetime between timezones.

Parameters:

ParameterTypeRequiredDescription
datetime_strstringYesDatetime to convert
from_timezonestringYesSource timezone
to_timezonestringYesTarget timezone
output_formatstringNoOutput format (strftime format string, default: “%Y-%m-%d %H:%M:%S %Z”)

parse_date

Parse date strings in various formats.

Parameters:

ParameterTypeRequiredDescription
date_strstringYesDate string to parse
output_formatstringNoOutput format (strftime format string, default: “%Y-%m-%d %H:%M:%S”)

Supported Formats:

  • 2024-12-25
  • December 25, 2024
  • 25/12/2024
  • 12-25-2024

Text Processing

word_count

Count words, characters, lines, and sentences.

Parameters:

ParameterTypeRequiredDescription
textstringYesText to analyze

Returns:

{
  "words": 150,
  "characters": 823,
  "lines": 12,
  "sentences": 8
}

find_replace

Find and replace text with regex support.

Parameters:

ParameterTypeRequiredDescription
textstringYesInput text
findstringYesPattern to find
replacestringYesReplacement text
use_regexboolNoUse regex (default: false)
case_sensitiveboolNoCase sensitive (default: true)

extract_urls

Extract all URLs from text.

Parameters:

ParameterTypeRequiredDescription
textstringYesText to extract URLs from

Returns: List of URLs found


extract_emails

Extract all email addresses from text.

Parameters:

ParameterTypeRequiredDescription
textstringYesText to extract emails from

Returns: List of email addresses found


text_compare

Compare two texts and show differences.

Parameters:

ParameterTypeRequiredDescription
text1stringYesFirst text
text2stringYesSecond text

Returns: Diff output showing additions and deletions


split_text

Split text by delimiter.

Parameters:

ParameterTypeRequiredDescription
textstringYesText to split
delimiterstringNoDelimiter (default: newline)
max_partsintNoMaximum number of parts to split into

trim_text

Trim text to maximum length.

Parameters:

ParameterTypeRequiredDescription
textstringYesText to trim
max_lengthintYesMaximum length
add_ellipsisboolNoWhether to add ’…’ when truncated (default: true)

JSON Processing

parse_json

Parse and validate JSON strings.

Parameters:

ParameterTypeRequiredDescription
json_strstringYesJSON string to parse

Returns: Parsed object or validation error


format_json

Pretty-print JSON with indentation.

Parameters:

ParameterTypeRequiredDescription
json_strstringYesJSON to format
indentintNoIndentation level (default: 2)

query_json

Query JSON using path expressions.

Parameters:

ParameterTypeRequiredDescription
json_strstringYesJSON to query
pathstringYesQuery path (e.g., data.users[0].name)

Path Syntax:

data.users         → Access 'users' in 'data'
data.users[0]      → First element of array
data.users[-1]     → Last element of array
data.users[*].name → All 'name' fields in array

extract_json

Extract JSON from mixed text content.

Parameters:

ParameterTypeRequiredDescription
textstringYesText containing JSON

Returns: Extracted JSON object(s)


json_to_text

Convert JSON to human-readable text.

Parameters:

ParameterTypeRequiredDescription
json_strstringYesJSON to convert

NLP Tools

analyze_sentiment

Analyze text sentiment.

Parameters:

ParameterTypeRequiredDescription
textstringYesText to analyze

Returns:

{
  "sentiment": "positive",
  "polarity": 0.75,
  "subjectivity": 0.6
}
  • polarity: -1.0 (negative) to 1.0 (positive)
  • subjectivity: 0.0 (objective) to 1.0 (subjective)

summarize_text

Summarize long text by extracting important sentences.

Parameters:

ParameterTypeRequiredDescription
textstringYesText to summarize
num_sentencesintNoNumber of sentences (default: 3)

extract_keywords

Extract the most important keywords from text.

Parameters:

ParameterTypeRequiredDescription
textstringYesText to analyze
num_keywordsintNoNumber of keywords (default: 10)