Add comprehensive documentation website with Sphinx

- Add complete Sphinx documentation structure
- Include API reference, tutorials, and examples
- Add GitHub Actions workflow for auto-deployment
- Include custom CSS and JavaScript for enhanced UI
- Add Makefile with build commands
- Include requirements for documentation dependencies
- Add quick start tutorial and getting started guide
- Configure Read the Docs theme with custom styling
- Add spell checking, link checking, and quality tools
- Set up automatic deployment to GitHub Pages

Documentation includes:
- Getting started guide with installation and basic usage
- Comprehensive examples for all major features
- Complete API reference with type hints
- Tutorials for different use cases
- Custom styling with SemantiCore branding
- Mobile-responsive design
- Dark mode support
- Performance optimization guides
This commit is contained in:
KaifAhmad1
2025-06-26 18:31:50 +05:30
parent e179e890d3
commit ba0c659700
13 changed files with 3095 additions and 0 deletions
+148
View File
@@ -0,0 +1,148 @@
name: Build and Deploy Documentation
on:
push:
branches: [ main, develop ]
paths: [ 'docs/**', 'semanticore/**', 'README.md', 'pyproject.toml' ]
pull_request:
branches: [ main ]
paths: [ 'docs/**', 'semanticore/**', 'README.md', 'pyproject.toml' ]
workflow_dispatch:
jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[docs,dev]"
pip install sphinx-rtd-theme sphinx-copybutton sphinx-tabs
- name: Build documentation
run: |
cd docs
make html
make linkcheck
- name: Upload documentation artifacts
uses: actions/upload-artifact@v3
with:
name: documentation
path: docs/_build/html/
deploy-docs:
needs: build-docs
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download documentation artifacts
uses: actions/download-artifact@v3
with:
name: documentation
path: docs/_build/html/
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build/html
cname: semanticore.readthedocs.io
test-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[docs,dev]"
pip install sphinx-rtd-theme sphinx-copybutton sphinx-tabs
- name: Test documentation build
run: |
cd docs
make html
make linkcheck
make doctest
- name: Check for broken links
run: |
cd docs
make linkcheck 2>&1 | tee linkcheck.log
if grep -q "broken" linkcheck.log; then
echo "Broken links found in documentation"
cat linkcheck.log
exit 1
fi
lint-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install doc8 sphinx-lint
- name: Lint documentation
run: |
doc8 docs/
sphinx-lint docs/
spell-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install sphinxcontrib-spelling
- name: Spell check documentation
run: |
cd docs
make spelling
+115
View File
@@ -0,0 +1,115 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Custom targets for SemantiCore documentation
# Build all documentation formats
all: html pdf epub
# Build HTML documentation
html:
@echo "Building HTML documentation..."
@$(SPHINXBUILD) -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS) $(O)
@echo "HTML documentation built in $(BUILDDIR)/html/"
# Build PDF documentation
pdf:
@echo "Building PDF documentation..."
@$(SPHINXBUILD) -b latex "$(SOURCEDIR)" "$(BUILDDIR)/latex" $(SPHINXOPTS) $(O)
@echo "Running LaTeX..."
$(MAKE) -C "$(BUILDDIR)/latex" all-pdf
@echo "PDF documentation built in $(BUILDDIR)/latex/"
# Build EPUB documentation
epub:
@echo "Building EPUB documentation..."
@$(SPHINXBUILD) -b epub "$(SOURCEDIR)" "$(BUILDDIR)/epub" $(SPHINXOPTS) $(O)
@echo "EPUB documentation built in $(BUILDDIR)/epub/"
# Clean build directory
clean:
@echo "Cleaning build directory..."
rm -rf "$(BUILDDIR)"
@echo "Build directory cleaned."
# Check for broken links
linkcheck:
@echo "Checking for broken links..."
@$(SPHINXBUILD) -b linkcheck "$(SOURCEDIR)" "$(BUILDDIR)/linkcheck" $(SPHINXOPTS) $(O)
@echo "Link check completed."
# Run doctests
doctest:
@echo "Running doctests..."
@$(SPHINXBUILD) -b doctest "$(SOURCEDIR)" "$(BUILDDIR)/doctest" $(SPHINXOPTS) $(O)
@echo "Doctests completed."
# Spell check
spelling:
@echo "Running spell check..."
@$(SPHINXBUILD) -b spelling "$(SOURCEDIR)" "$(BUILDDIR)/spelling" $(SPHINXOPTS) $(O)
@echo "Spell check completed."
# Serve documentation locally
serve:
@echo "Starting local documentation server..."
@cd "$(BUILDDIR)/html" && python -m http.server 8000
@echo "Documentation available at http://localhost:8000"
# Build and serve
dev: html serve
# Full documentation build with all checks
full: clean html linkcheck doctest
@echo "Full documentation build completed."
# Install dependencies for documentation
install-deps:
@echo "Installing documentation dependencies..."
pip install sphinx sphinx-rtd-theme sphinx-copybutton sphinx-tabs myst-parser
pip install sphinxcontrib-spelling doc8 sphinx-lint
@echo "Documentation dependencies installed."
# Generate API documentation
api:
@echo "Generating API documentation..."
sphinx-apidoc -o api ../semanticore --force --module-first --no-toc
@echo "API documentation generated."
# Update all documentation
update: api html
@echo "Documentation updated."
# Deploy to GitHub Pages (requires gh-pages branch)
deploy: html
@echo "Deploying to GitHub Pages..."
@if [ -d "$(BUILDDIR)/html" ]; then \
git checkout gh-pages; \
cp -r "$(BUILDDIR)/html/"* .; \
git add .; \
git commit -m "Update documentation"; \
git push origin gh-pages; \
git checkout main; \
echo "Documentation deployed to GitHub Pages."; \
else \
echo "Error: HTML documentation not found. Run 'make html' first."; \
exit 1; \
fi
+362
View File
@@ -0,0 +1,362 @@
# SemantiCore Documentation
This directory contains the complete documentation for SemantiCore, built using Sphinx.
## 📁 Directory Structure
```
docs/
├── conf.py # Sphinx configuration
├── index.rst # Main documentation index
├── getting_started.rst # Getting started guide
├── examples.rst # Comprehensive examples
├── api/ # API documentation
│ └── index.rst # API reference index
├── tutorials/ # Tutorial guides
├── examples/ # Code examples
├── _static/ # Static assets
│ ├── css/ # Custom CSS
│ │ └── custom.css
│ └── js/ # Custom JavaScript
│ └── custom.js
├── _templates/ # Custom templates
├── Makefile # Build commands
└── README.md # This file
```
## 🚀 Quick Start
### Prerequisites
- Python 3.8+
- pip
### Installation
1. **Install documentation dependencies:**
```bash
pip install -e ".[docs]"
```
2. **Or install manually:**
```bash
pip install sphinx sphinx-rtd-theme sphinx-copybutton sphinx-tabs myst-parser
```
### Building Documentation
1. **Build HTML documentation:**
```bash
cd docs
make html
```
2. **Serve locally:**
```bash
make serve
```
3. **Build all formats:**
```bash
make all
```
## 📋 Available Commands
### Basic Commands
- `make html` - Build HTML documentation
- `make pdf` - Build PDF documentation
- `make epub` - Build EPUB documentation
- `make clean` - Clean build directory
### Quality Checks
- `make linkcheck` - Check for broken links
- `make doctest` - Run doctests
- `make spelling` - Spell check documentation
### Development
- `make serve` - Serve documentation locally
- `make dev` - Build and serve (development)
- `make full` - Full build with all checks
### Advanced
- `make install-deps` - Install documentation dependencies
- `make api` - Generate API documentation
- `make update` - Update all documentation
- `make deploy` - Deploy to GitHub Pages
## 🎨 Customization
### CSS Customization
Edit `_static/css/custom.css` to customize the appearance:
```css
:root {
--semanticore-primary: #2980B9;
--semanticore-secondary: #27AE60;
--semanticore-accent: #8E44AD;
}
```
### JavaScript Customization
Edit `_static/js/custom.js` to add interactive features:
```javascript
// Add custom functionality
document.addEventListener('DOMContentLoaded', function() {
// Your custom code here
});
```
### Theme Configuration
Modify `conf.py` to change theme options:
```python
html_theme_options = {
'navigation_depth': 4,
'titles_only': False,
'collapse_navigation': False,
'sticky_navigation': True,
}
```
## 📝 Writing Documentation
### RST Files
Use reStructuredText (RST) for documentation:
```rst
Title
=====
Section
--------
Subsection
~~~~~~~~~~
.. code-block:: python
def example():
return "Hello, World!"
.. note::
This is a note.
.. warning::
This is a warning.
```
### Markdown Files
Use MyST Markdown for simpler syntax:
```markdown
# Title
## Section
### Subsection
```python
def example():
return "Hello, World!"
```
::: note
This is a note.
:::
::: warning
This is a warning.
:::
```
### Code Examples
Include code examples with syntax highlighting:
```rst
.. code-block:: python
from semanticore import SemantiCore
core = SemantiCore()
result = core.process_document("document.pdf")
```
### API Documentation
Use autodoc for automatic API documentation:
```rst
.. automodule:: semanticore.core.engine
:members:
:undoc-members:
:show-inheritance:
```
## 🔧 Configuration
### Sphinx Configuration
Key settings in `conf.py`:
- **Extensions**: List of Sphinx extensions
- **Theme**: Read the Docs theme
- **Static files**: CSS and JavaScript
- **Intersphinx**: Links to other documentation
### Build Configuration
Environment variables:
```bash
export SPHINXOPTS="-W --keep-going"
export SPHINXBUILD=sphinx-build
```
## 🚀 Deployment
### GitHub Pages
1. **Automatic deployment** (via GitHub Actions):
- Push to `main` branch
- Documentation builds automatically
- Deployed to `gh-pages` branch
2. **Manual deployment**:
```bash
make deploy
```
### Read the Docs
1. Connect repository to Read the Docs
2. Documentation builds automatically
3. Available at `https://semanticore.readthedocs.io`
## 🧪 Testing
### Link Checking
```bash
make linkcheck
```
### Spell Checking
```bash
make spelling
```
### Doctests
```bash
make doctest
```
### Full Test Suite
```bash
make full
```
## 📊 Analytics
The documentation includes Google Analytics 4 tracking:
- Page views
- User engagement
- Performance metrics
Configure in `_static/js/custom.js`:
```javascript
gtag('config', 'G-XXXXXXXXXX'); // Replace with actual GA4 ID
```
## 🤝 Contributing
### Adding New Documentation
1. Create new RST or MD file
2. Add to appropriate toctree
3. Follow style guidelines
4. Test locally before submitting
### Style Guidelines
- Use clear, concise language
- Include code examples
- Add appropriate warnings/notes
- Test all links
- Spell check content
### Review Process
1. Build documentation locally
2. Check for broken links
3. Verify code examples work
4. Submit pull request
5. Automated checks run
6. Manual review by maintainers
## 🐛 Troubleshooting
### Common Issues
**Build fails with import errors:**
```bash
pip install -e ".[docs]"
```
**Missing dependencies:**
```bash
make install-deps
```
**Broken links:**
```bash
make linkcheck
```
**Spelling errors:**
```bash
make spelling
```
### Performance Issues
- Use `make clean` before rebuilding
- Check for large images
- Optimize CSS/JS files
- Use appropriate image formats
## 📚 Resources
- [Sphinx Documentation](https://www.sphinx-doc.org/)
- [Read the Docs Theme](https://sphinx-rtd-theme.readthedocs.io/)
- [MyST Markdown](https://myst-parser.readthedocs.io/)
- [reStructuredText](https://docutils.sourceforge.io/rst.html)
## 📞 Support
- **Documentation Issues**: GitHub Issues
- **Questions**: GitHub Discussions
- **Community**: Discord Server
- **Email**: docs@semanticore.io
---
*This documentation is built with ❤️ by the SemantiCore community.*
+331
View File
@@ -0,0 +1,331 @@
/* Custom CSS for SemantiCore Documentation */
/* Custom color scheme */
:root {
--semanticore-primary: #2980B9;
--semanticore-secondary: #27AE60;
--semanticore-accent: #8E44AD;
--semanticore-warning: #F39C12;
--semanticore-danger: #E74C3C;
--semanticore-light: #ECF0F1;
--semanticore-dark: #2C3E50;
}
/* Header styling */
.wy-side-nav-search {
background-color: var(--semanticore-primary);
}
.wy-side-nav-search input[type="text"] {
border-color: var(--semanticore-primary);
}
/* Navigation styling */
.wy-nav-side {
background-color: var(--semanticore-dark);
}
.wy-menu-vertical a {
color: #b3b3b3;
}
.wy-menu-vertical a:hover {
background-color: var(--semanticore-primary);
color: white;
}
.wy-menu-vertical li.current > a {
background-color: var(--semanticore-primary);
color: white;
}
/* Content styling */
.wy-nav-content {
background-color: white;
}
.wy-nav-content-wrap {
background-color: white;
}
/* Code blocks */
.highlight {
background-color: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 4px;
padding: 1rem;
}
.highlight pre {
background-color: transparent;
border: none;
padding: 0;
}
/* Copy button styling */
.copybutton {
background-color: var(--semanticore-primary);
color: white;
border: none;
border-radius: 4px;
padding: 4px 8px;
font-size: 12px;
cursor: pointer;
transition: background-color 0.3s;
}
.copybutton:hover {
background-color: #1f5f8b;
}
/* Button styling */
.btn {
display: inline-block;
padding: 10px 20px;
margin: 5px;
text-decoration: none;
border-radius: 5px;
font-weight: 500;
transition: all 0.3s ease;
}
.btn-primary {
background-color: var(--semanticore-primary);
color: white;
}
.btn-primary:hover {
background-color: #1f5f8b;
color: white;
text-decoration: none;
}
.btn-secondary {
background-color: var(--semanticore-secondary);
color: white;
}
.btn-secondary:hover {
background-color: #1e8449;
color: white;
text-decoration: none;
}
.btn-info {
background-color: var(--semanticore-accent);
color: white;
}
.btn-info:hover {
background-color: #6c3483;
color: white;
text-decoration: none;
}
.btn-dark {
background-color: var(--semanticore-dark);
color: white;
}
.btn-dark:hover {
background-color: #1a252f;
color: white;
text-decoration: none;
}
/* Alert boxes */
.alert {
padding: 15px;
margin: 20px 0;
border-radius: 5px;
border-left: 4px solid;
}
.alert-info {
background-color: #e8f4fd;
border-color: var(--semanticore-primary);
color: #0c5460;
}
.alert-success {
background-color: #d4edda;
border-color: var(--semanticore-secondary);
color: #155724;
}
.alert-warning {
background-color: #fff3cd;
border-color: var(--semanticore-warning);
color: #856404;
}
.alert-danger {
background-color: #f8d7da;
border-color: var(--semanticore-danger);
color: #721c24;
}
/* Table styling */
.wy-table-responsive table {
border-collapse: collapse;
width: 100%;
margin: 1rem 0;
}
.wy-table-responsive th {
background-color: var(--semanticore-primary);
color: white;
padding: 12px;
text-align: left;
}
.wy-table-responsive td {
padding: 12px;
border-bottom: 1px solid #e9ecef;
}
.wy-table-responsive tr:nth-child(even) {
background-color: #f8f9fa;
}
.wy-table-responsive tr:hover {
background-color: #e9ecef;
}
/* Admonition styling */
.admonition {
border-radius: 5px;
margin: 1rem 0;
}
.admonition-title {
font-weight: bold;
padding: 10px 15px;
border-radius: 5px 5px 0 0;
}
.admonition.note {
background-color: #e8f4fd;
border-left: 4px solid var(--semanticore-primary);
}
.admonition.note .admonition-title {
background-color: var(--semanticore-primary);
color: white;
}
.admonition.warning {
background-color: #fff3cd;
border-left: 4px solid var(--semanticore-warning);
}
.admonition.warning .admonition-title {
background-color: var(--semanticore-warning);
color: white;
}
.admonition.tip {
background-color: #d4edda;
border-left: 4px solid var(--semanticore-secondary);
}
.admonition.tip .admonition-title {
background-color: var(--semanticore-secondary);
color: white;
}
/* Code inline styling */
code {
background-color: #f8f9fa;
color: var(--semanticore-primary);
padding: 2px 4px;
border-radius: 3px;
font-size: 0.9em;
}
/* Footer styling */
.wy-nav-content footer {
background-color: var(--semanticore-dark);
color: white;
padding: 20px 0;
margin-top: 40px;
text-align: center;
}
/* Responsive design */
@media (max-width: 768px) {
.wy-nav-side {
width: 100%;
position: relative;
}
.wy-nav-content {
margin-left: 0;
}
.btn {
display: block;
margin: 5px 0;
text-align: center;
}
}
/* Dark mode support */
@media (prefers-color-scheme: dark) {
.wy-nav-content {
background-color: #1a1a1a;
color: #e0e0e0;
}
.wy-nav-content-wrap {
background-color: #1a1a1a;
}
.highlight {
background-color: #2d2d2d;
border-color: #404040;
}
code {
background-color: #2d2d2d;
color: #e0e0e0;
}
}
/* Animation for interactive elements */
.btn, .copybutton, .wy-menu-vertical a {
transition: all 0.3s ease;
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: var(--semanticore-primary);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #1f5f8b;
}
/* Print styles */
@media print {
.wy-nav-side,
.wy-nav-content-wrap .wy-nav-content {
background: white !important;
color: black !important;
}
.btn {
border: 1px solid black;
background: white !important;
color: black !important;
}
}
+334
View File
@@ -0,0 +1,334 @@
// Custom JavaScript for SemantiCore Documentation
document.addEventListener('DOMContentLoaded', function() {
// Initialize copy buttons
initializeCopyButtons();
// Initialize search functionality
initializeSearch();
// Initialize smooth scrolling
initializeSmoothScrolling();
// Initialize code highlighting
initializeCodeHighlighting();
// Initialize mobile menu
initializeMobileMenu();
// Initialize dark mode toggle
initializeDarkMode();
// Initialize analytics
initializeAnalytics();
});
// Copy button functionality
function initializeCopyButtons() {
const copyButtons = document.querySelectorAll('.copybutton');
copyButtons.forEach(button => {
button.addEventListener('click', function() {
const codeBlock = this.parentElement.querySelector('pre');
const text = codeBlock.textContent;
navigator.clipboard.writeText(text).then(() => {
// Show success message
const originalText = this.textContent;
this.textContent = 'Copied!';
this.style.backgroundColor = '#27AE60';
setTimeout(() => {
this.textContent = originalText;
this.style.backgroundColor = '';
}, 2000);
}).catch(err => {
console.error('Failed to copy text: ', err);
// Fallback for older browsers
fallbackCopyTextToClipboard(text, this);
});
});
});
}
// Fallback copy function for older browsers
function fallbackCopyTextToClipboard(text, button) {
const textArea = document.createElement('textarea');
textArea.value = text;
textArea.style.position = 'fixed';
textArea.style.left = '-999999px';
textArea.style.top = '-999999px';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
const originalText = button.textContent;
button.textContent = 'Copied!';
button.style.backgroundColor = '#27AE60';
setTimeout(() => {
button.textContent = originalText;
button.style.backgroundColor = '';
}, 2000);
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
document.body.removeChild(textArea);
}
// Search functionality
function initializeSearch() {
const searchInput = document.querySelector('.wy-side-nav-search input[type="text"]');
if (searchInput) {
searchInput.addEventListener('input', function() {
const query = this.value.toLowerCase();
const menuItems = document.querySelectorAll('.wy-menu-vertical li');
menuItems.forEach(item => {
const link = item.querySelector('a');
if (link) {
const text = link.textContent.toLowerCase();
if (text.includes(query)) {
item.style.display = '';
} else {
item.style.display = 'none';
}
}
});
});
}
}
// Smooth scrolling for anchor links
function initializeSmoothScrolling() {
const links = document.querySelectorAll('a[href^="#"]');
links.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// Code highlighting
function initializeCodeHighlighting() {
// Add line numbers to code blocks
const codeBlocks = document.querySelectorAll('pre code');
codeBlocks.forEach(block => {
const lines = block.textContent.split('\n');
if (lines.length > 1) {
const lineNumbers = document.createElement('div');
lineNumbers.className = 'line-numbers';
lines.forEach((line, index) => {
const lineNumber = document.createElement('span');
lineNumber.textContent = index + 1;
lineNumber.className = 'line-number';
lineNumbers.appendChild(lineNumber);
});
block.parentElement.insertBefore(lineNumbers, block);
}
});
}
// Mobile menu functionality
function initializeMobileMenu() {
const menuToggle = document.querySelector('.wy-nav-top .wy-menu-toggle');
const navSide = document.querySelector('.wy-nav-side');
if (menuToggle && navSide) {
menuToggle.addEventListener('click', function() {
navSide.classList.toggle('nav-open');
});
// Close menu when clicking outside
document.addEventListener('click', function(e) {
if (!navSide.contains(e.target) && !menuToggle.contains(e.target)) {
navSide.classList.remove('nav-open');
}
});
}
}
// Dark mode toggle
function initializeDarkMode() {
const darkModeToggle = document.createElement('button');
darkModeToggle.className = 'dark-mode-toggle';
darkModeToggle.innerHTML = '🌙';
darkModeToggle.title = 'Toggle dark mode';
// Check for saved dark mode preference
const darkMode = localStorage.getItem('darkMode');
if (darkMode === 'enabled') {
document.body.classList.add('dark-mode');
darkModeToggle.innerHTML = '☀️';
}
darkModeToggle.addEventListener('click', function() {
document.body.classList.toggle('dark-mode');
if (document.body.classList.contains('dark-mode')) {
localStorage.setItem('darkMode', 'enabled');
this.innerHTML = '☀️';
} else {
localStorage.setItem('darkMode', null);
this.innerHTML = '🌙';
}
});
// Add toggle button to navigation
const navTop = document.querySelector('.wy-nav-top');
if (navTop) {
navTop.appendChild(darkModeToggle);
}
}
// Analytics (Google Analytics 4)
function initializeAnalytics() {
// Only load analytics in production
if (window.location.hostname === 'semanticore.readthedocs.io') {
// Google Analytics 4
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX'); // Replace with actual GA4 ID
// Load Google Analytics script
const script = document.createElement('script');
script.async = true;
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX'; // Replace with actual GA4 ID
document.head.appendChild(script);
// Track page views
gtag('config', 'G-XXXXXXXXXX', {
page_title: document.title,
page_location: window.location.href
});
}
}
// Progress bar for reading
function initializeProgressBar() {
const progressBar = document.createElement('div');
progressBar.className = 'reading-progress';
progressBar.innerHTML = '<div class="progress-fill"></div>';
document.body.appendChild(progressBar);
window.addEventListener('scroll', function() {
const scrollTop = window.pageYOffset;
const docHeight = document.body.scrollHeight - window.innerHeight;
const scrollPercent = (scrollTop / docHeight) * 100;
const progressFill = progressBar.querySelector('.progress-fill');
progressFill.style.width = scrollPercent + '%';
});
}
// Table of contents highlighting
function initializeTOCHighlighting() {
const headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
const tocLinks = document.querySelectorAll('.wy-menu-vertical a[href^="#"]');
window.addEventListener('scroll', function() {
let current = '';
headings.forEach(heading => {
const sectionTop = heading.offsetTop;
const sectionHeight = heading.clientHeight;
if (window.pageYOffset >= sectionTop - 200) {
current = heading.getAttribute('id');
}
});
tocLinks.forEach(link => {
link.classList.remove('current');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('current');
}
});
});
}
// Keyboard shortcuts
function initializeKeyboardShortcuts() {
document.addEventListener('keydown', function(e) {
// Ctrl/Cmd + K for search
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
const searchInput = document.querySelector('.wy-side-nav-search input[type="text"]');
if (searchInput) {
searchInput.focus();
}
}
// Escape to close mobile menu
if (e.key === 'Escape') {
const navSide = document.querySelector('.wy-nav-side');
if (navSide) {
navSide.classList.remove('nav-open');
}
}
// Ctrl/Cmd + / for toggle dark mode
if ((e.ctrlKey || e.metaKey) && e.key === '/') {
e.preventDefault();
const darkModeToggle = document.querySelector('.dark-mode-toggle');
if (darkModeToggle) {
darkModeToggle.click();
}
}
});
}
// Initialize additional features
document.addEventListener('DOMContentLoaded', function() {
initializeProgressBar();
initializeTOCHighlighting();
initializeKeyboardShortcuts();
});
// Performance monitoring
function initializePerformanceMonitoring() {
// Monitor page load time
window.addEventListener('load', function() {
const loadTime = performance.timing.loadEventEnd - performance.timing.navigationStart;
console.log('Page load time:', loadTime + 'ms');
// Send to analytics if available
if (typeof gtag !== 'undefined') {
gtag('event', 'timing_complete', {
name: 'load',
value: loadTime
});
}
});
// Monitor scroll performance
let scrollTimeout;
window.addEventListener('scroll', function() {
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(function() {
// Log scroll events for performance analysis
console.log('Scroll event processed');
}, 100);
});
}
// Initialize performance monitoring
initializePerformanceMonitoring();
+256
View File
@@ -0,0 +1,256 @@
API Reference
=============
Welcome to the SemantiCore API reference. This section provides comprehensive documentation for all SemantiCore modules, classes, and functions.
Core Modules
------------
.. toctree::
:maxdepth: 2
core
processors
extraction
embeddings
knowledge_graph
streaming
domains
Quick API Overview
------------------
**Main Entry Point**
.. code-block:: python
from semanticore import SemantiCore
# Initialize the main engine
core = SemantiCore(
llm_provider="openai",
embedding_model="text-embedding-3-large",
vector_store="pinecone",
graph_db="neo4j"
)
**Document Processing**
.. code-block:: python
from semanticore.processors import DocumentProcessor
processor = DocumentProcessor()
result = processor.process("document.pdf")
**Semantic Extraction**
.. code-block:: python
from semanticore.extraction import TripleExtractor
extractor = TripleExtractor()
triples = extractor.extract_triples(text)
**Knowledge Graph**
.. code-block:: python
from semanticore.knowledge_graph import KnowledgeGraphBuilder
builder = KnowledgeGraphBuilder()
builder.add_triples(triples)
builder.build()
**Vector Embeddings**
.. code-block:: python
from semanticore.embeddings import SemanticEmbedder
embedder = SemanticEmbedder()
embeddings = embedder.generate_embeddings(documents)
Module Structure
----------------
.. code-block:: text
semanticore/
├── core/ # Core framework
│ ├── engine.py # Main SemantiCore engine
│ ├── config.py # Configuration management
│ └── exceptions.py # Custom exceptions
├── processors/ # Data processing modules
│ ├── document/ # Document processing
│ ├── web/ # Web content processing
│ ├── structured/ # Structured data processing
│ └── base.py # Base processor class
├── extraction/ # Semantic extraction
│ ├── entities.py # Entity extraction
│ ├── relationships.py # Relationship extraction
│ └── triples.py # Triple generation
├── embeddings/ # Embedding generation
│ ├── text_embeddings.py
│ └── vector_stores.py
├── knowledge_graph/ # Knowledge graph construction
│ ├── builder.py
│ └── storage.py
├── streaming/ # Real-time processing
│ └── feed_processor.py
└── domains/ # Domain-specific processors
├── cybersecurity/
├── biomedical/
└── finance/
Configuration
-------------
SemantiCore can be configured through various methods:
**Environment Variables**
.. code-block:: bash
export SEMANTICORE_LLM_PROVIDER=openai
export SEMANTICORE_EMBEDDING_MODEL=text-embedding-3-large
export SEMANTICORE_VECTOR_STORE=pinecone
export SEMANTICORE_GRAPH_DB=neo4j
**Configuration File**
.. code-block:: yaml
llm:
provider: openai
model: gpt-4
api_key: ${OPENAI_API_KEY}
embeddings:
model: text-embedding-3-large
dimension: 1536
vector_store:
provider: pinecone
api_key: ${PINECONE_API_KEY}
knowledge_graph:
provider: neo4j
uri: bolt://localhost:7687
**Programmatic Configuration**
.. code-block:: python
config = {
"llm": {
"provider": "openai",
"model": "gpt-4",
"api_key": "your-api-key"
},
"embeddings": {
"model": "text-embedding-3-large",
"dimension": 1536
}
}
core = SemantiCore(config=config)
Error Handling
--------------
SemantiCore provides comprehensive error handling:
.. code-block:: python
from semanticore.core.exceptions import (
SemantiCoreError,
ProcessingError,
ConfigurationError,
ValidationError
)
try:
result = core.process_document("document.pdf")
except ProcessingError as e:
print(f"Processing failed: {e}")
except ConfigurationError as e:
print(f"Configuration error: {e}")
except SemantiCoreError as e:
print(f"General error: {e}")
Type Hints
----------
All SemantiCore functions include comprehensive type hints:
.. code-block:: python
from typing import List, Dict, Optional, Union
from semanticore.core.types import (
ProcessedContent,
Entity,
Triple,
Embedding,
KnowledgeBase
)
def process_documents(
self,
sources: List[str],
config: Optional[Dict] = None
) -> List[ProcessedContent]:
"""Process multiple documents."""
pass
Performance Considerations
-------------------------
**Batch Processing**
.. code-block:: python
# Process documents in batches for better performance
batch_size = 100
for i in range(0, len(documents), batch_size):
batch = documents[i:i + batch_size]
results = core.process_documents(batch)
**Memory Management**
.. code-block:: python
# Use generators for large datasets
def document_generator():
for doc in large_dataset:
yield doc
for result in core.process_documents_stream(document_generator()):
process_result(result)
**Parallel Processing**
.. code-block:: python
# Enable parallel processing
core = SemantiCore(
config={
"processing": {
"max_workers": 4,
"batch_size": 50
}
}
)
Best Practices
--------------
1. **Use appropriate batch sizes** for your hardware
2. **Handle errors gracefully** with try-catch blocks
3. **Monitor memory usage** for large datasets
4. **Use type hints** for better code quality
5. **Configure logging** for debugging
6. **Validate inputs** before processing
7. **Use async/await** for I/O operations
8. **Cache results** when appropriate
.. raw:: html
<div style="text-align: center; margin: 20px 0; padding: 15px; background-color: #fff3cd; border-left: 4px solid #ffc107; border-radius: 5px;">
<strong>📚 Note:</strong> This API reference is generated from the source code. For the most up-to-date information, check the source code or run <code>help()</code> on any SemantiCore object.
</div>
BIN
View File
Binary file not shown.
+687
View File
@@ -0,0 +1,687 @@
SemantiCore Examples
====================
This page provides comprehensive examples of SemantiCore usage across different domains and use cases.
Basic Examples
--------------
**Simple Document Processing**
.. code-block:: python
from semanticore import SemantiCore
# Initialize SemantiCore
core = SemantiCore()
# Process a single document
result = core.process_document("financial_report.pdf")
print(f"Extracted {len(result.entities)} entities")
print(f"Generated {len(result.triples)} triples")
print(f"Created {len(result.embeddings)} embeddings")
**Batch Processing Multiple Documents**
.. code-block:: python
from semanticore import SemantiCore
core = SemantiCore()
# Process multiple documents
documents = [
"report1.pdf",
"report2.docx",
"data.json",
"https://example.com/article"
]
results = core.process_documents(documents)
for doc, result in zip(documents, results):
print(f"{doc}: {len(result.entities)} entities, {len(result.triples)} triples")
**Custom Configuration**
.. code-block:: python
from semanticore import SemantiCore
# Initialize with custom configuration
core = SemantiCore(
llm_provider="openai",
embedding_model="text-embedding-3-large",
vector_store="pinecone",
graph_db="neo4j",
config={
"processing": {
"batch_size": 50,
"max_workers": 4,
"timeout": 300
},
"extraction": {
"confidence_threshold": 0.8,
"include_implicit_relations": True
}
}
)
Document Processing Examples
---------------------------
**PDF Document with Tables and Images**
.. code-block:: python
from semanticore.processors.document import PDFProcessor
# Initialize PDF processor with advanced features
pdf_processor = PDFProcessor(
extract_tables=True,
extract_images=True,
extract_metadata=True,
preserve_structure=True,
ocr_enabled=True
)
# Process PDF
result = pdf_processor.process("financial_report.pdf")
# Access extracted content
print(f"Text content: {len(result.text)} characters")
print(f"Tables extracted: {len(result.tables)}")
print(f"Images extracted: {len(result.images)}")
print(f"Metadata: {result.metadata}")
**Office Documents (Word, PowerPoint, Excel)**
.. code-block:: python
from semanticore.processors.document import (
DOCXProcessor, PPTXProcessor, ExcelProcessor
)
# Process Word document
docx_processor = DOCXProcessor(extract_comments=True)
docx_result = docx_processor.process("document.docx")
# Process PowerPoint presentation
pptx_processor = PPTXProcessor(extract_notes=True)
pptx_result = pptx_processor.process("presentation.pptx")
# Process Excel spreadsheet
excel_processor = ExcelProcessor(extract_formulas=True)
excel_result = excel_processor.process("data.xlsx")
# Combine results
all_content = docx_result + pptx_result + excel_result
Web Content Processing
----------------------
**RSS Feed Monitoring**
.. code-block:: python
from semanticore.processors.web import FeedProcessor
import asyncio
async def monitor_feeds():
# Initialize feed processor
feed_processor = FeedProcessor(
update_interval="5m",
deduplicate=True,
extract_full_content=True
)
# Subscribe to feeds
feeds = [
"https://feeds.feedburner.com/TechCrunch",
"https://rss.cnn.com/rss/edition.rss",
"https://feeds.reuters.com/reuters/topNews"
]
for feed_url in feeds:
feed_processor.subscribe(feed_url, category="news")
# Process items in real-time
async for feed_item in feed_processor.stream():
print(f"New item: {feed_item.title}")
# Extract semantics
semantics = core.extract_semantics(feed_item.content)
triples = core.generate_triples(semantics)
# Update knowledge graph
knowledge_graph.add_triples(triples)
# Run the feed monitor
asyncio.run(monitor_feeds())
**Web Scraping with Semantic Understanding**
.. code-block:: python
from semanticore.processors.web import WebProcessor
# Initialize web processor
web_processor = WebProcessor(
respect_robots=True,
extract_metadata=True,
follow_redirects=True,
max_depth=3,
user_agent="SemantiCore Bot/1.0"
)
# Process web pages
urls = [
"https://example.com/article1",
"https://example.com/article2",
"https://example.com/article3"
]
for url in urls:
webpage = web_processor.process_url(url)
# Extract semantic information
semantics = core.extract_semantics(webpage.content)
entities = core.extract_entities(webpage.content)
triples = core.generate_triples(semantics)
print(f"URL: {url}")
print(f"Entities: {len(entities)}")
print(f"Triples: {len(triples)}")
Semantic Extraction Examples
----------------------------
**Entity and Relationship Extraction**
.. code-block:: python
from semanticore.extraction import EntityExtractor, RelationshipExtractor
# Initialize extractors
entity_extractor = EntityExtractor(
model="en_core_web_sm",
entity_types=["PERSON", "ORG", "GPE", "DATE", "MONEY"]
)
relationship_extractor = RelationshipExtractor(
confidence_threshold=0.7,
include_implicit_relations=True
)
# Extract entities and relationships
text = """
Apple Inc. was founded by Steve Jobs in 1976 in Cupertino, California.
The company's revenue in 2023 was $394.33 billion.
Tim Cook is the current CEO of Apple.
"""
entities = entity_extractor.extract_entities(text)
relationships = relationship_extractor.extract_relationships(text, entities)
print("Entities found:")
for entity in entities:
print(f" {entity.text} ({entity.type}) - Confidence: {entity.confidence}")
print("\nRelationships found:")
for rel in relationships:
print(f" {rel.subject} --{rel.predicate}--> {rel.object}")
**Triple Generation**
.. code-block:: python
from semanticore.extraction import TripleExtractor
# Initialize triple extractor
triple_extractor = TripleExtractor(
confidence_threshold=0.8,
include_implicit_relations=True,
temporal_modeling=True,
spatial_modeling=True
)
# Extract triples from text
text = """
Microsoft Corporation was founded by Bill Gates and Paul Allen in 1975.
The company is headquartered in Redmond, Washington.
Satya Nadella became CEO in 2014.
Microsoft acquired LinkedIn in 2016 for $26.2 billion.
"""
triples = triple_extractor.extract_triples(text)
print("Generated Triples:")
for triple in triples:
print(f" {triple.subject} | {triple.predicate} | {triple.object}")
print(f" Confidence: {triple.confidence:.2f}")
# Export to different formats
turtle_format = triple_extractor.to_turtle(triples)
ntriples_format = triple_extractor.to_ntriples(triples)
jsonld_format = triple_extractor.to_jsonld(triples)
Knowledge Graph Examples
------------------------
**Building a Knowledge Graph**
.. code-block:: python
from semanticore.knowledge_graph import KnowledgeGraphBuilder
# Initialize knowledge graph builder
kg_builder = KnowledgeGraphBuilder(
storage_backend="neo4j",
uri="bolt://localhost:7687",
username="neo4j",
password="password"
)
# Add triples to the graph
triples = [
("Apple Inc.", "founded_by", "Steve Jobs"),
("Apple Inc.", "founded_in", "1976"),
("Apple Inc.", "located_in", "Cupertino"),
("Cupertino", "located_in", "California"),
("Steve Jobs", "co_founded", "Apple Inc."),
("Tim Cook", "is_CEO_of", "Apple Inc."),
("Apple Inc.", "revenue_2023", "$394.33 billion")
]
for subject, predicate, object in triples:
kg_builder.add_triple(subject, predicate, object)
# Build the knowledge graph
kg_builder.build()
# Query the knowledge graph
results = kg_builder.query("""
MATCH (e:Entity {name: "Apple Inc."})
OPTIONAL MATCH (e)-[r]->(o)
RETURN e.name, type(r), o.name
""")
for result in results:
print(f"{result['e.name']} --{result['type(r)']}--> {result['o.name']}")
**SPARQL Query Generation**
.. code-block:: python
from semanticore.knowledge_graph import SPARQLGenerator
# Initialize SPARQL generator
sparql_gen = SPARQLGenerator()
# Generate SPARQL queries
natural_query = "Who founded Apple Inc.?"
sparql_query = sparql_gen.generate_sparql(natural_query)
print(f"Natural Language: {natural_query}")
print(f"SPARQL Query: {sparql_query}")
# Execute the query
results = kg_builder.execute_sparql(sparql_query)
print(f"Results: {results}")
Vector Embeddings Examples
--------------------------
**Semantic Embeddings Generation**
.. code-block:: python
from semanticore.embeddings import SemanticEmbedder
# Initialize semantic embedder
embedder = SemanticEmbedder(
model="text-embedding-3-large",
dimension=1536,
preserve_context=True,
semantic_chunking=True
)
# Generate embeddings for documents
documents = [
"Artificial intelligence is transforming healthcare.",
"Machine learning algorithms improve patient outcomes.",
"AI-powered diagnostics reduce medical errors.",
"Healthcare technology advances rapidly."
]
# Generate embeddings
embeddings = embedder.generate_embeddings(documents)
print(f"Generated {len(embeddings)} embeddings")
print(f"Embedding dimension: {len(embeddings[0])}")
**Semantic Search**
.. code-block:: python
from semanticore.embeddings import VectorStore
# Initialize vector store
vector_store = VectorStore(
provider="pinecone",
api_key="your_pinecone_api_key",
environment="us-west1-gcp"
)
# Store embeddings
vector_store.store_embeddings(documents, embeddings)
# Semantic search
query = "How is AI used in medical diagnosis?"
results = vector_store.semantic_search(
query=query,
top_k=5,
include_metadata=True
)
print(f"Search results for: {query}")
for i, result in enumerate(results, 1):
print(f"{i}. {result.document} (Score: {result.score:.3f})")
**Multi-Modal Embeddings**
.. code-block:: python
from semanticore.embeddings import MultiModalEmbedder
# Initialize multi-modal embedder
mm_embedder = MultiModalEmbedder(
text_model="text-embedding-3-large",
image_model="clip-vit-base-patch32",
audio_model="whisper-base"
)
# Generate multi-modal embeddings
content = {
"text": "A chart showing quarterly revenue growth",
"image": "revenue_chart.png",
"audio": "earnings_call.mp3"
}
embeddings = mm_embedder.generate_embeddings(content)
print(f"Text embedding: {len(embeddings['text'])} dimensions")
print(f"Image embedding: {len(embeddings['image'])} dimensions")
print(f"Audio embedding: {len(embeddings['audio'])} dimensions")
Real-Time Processing Examples
-----------------------------
**Stream Processing with Kafka**
.. code-block:: python
from semanticore.streaming import KafkaProcessor
import asyncio
async def process_stream():
# Initialize Kafka processor
kafka_processor = KafkaProcessor(
bootstrap_servers=["localhost:9092"],
topics=["documents", "web_content", "feeds"],
group_id="semanticore-processor"
)
# Process streaming data
async for message in kafka_processor.consume():
content = message.value
# Determine content type and process accordingly
if message.headers.get("content_type") == "application/pdf":
processed = doc_processor.process_pdf_bytes(content)
elif message.headers.get("content_type") == "text/html":
processed = web_processor.process_html(content)
else:
processed = content
# Extract semantics and build knowledge
semantics = core.extract_semantics(processed)
triples = core.generate_triples(semantics)
knowledge_graph.add_triples(triples)
print(f"Processed message from topic: {message.topic}")
# Run the stream processor
asyncio.run(process_stream())
Domain-Specific Examples
------------------------
**Cybersecurity Intelligence**
.. code-block:: python
from semanticore.domains.cybersecurity import CyberIntelProcessor
# Initialize cybersecurity processor
cyber_processor = CyberIntelProcessor(
threat_feeds=[
"https://feeds.feedburner.com/CyberSecurityNewsDaily",
"https://www.us-cert.gov/ncas/current-activity.xml"
],
formats=["pdf", "html", "xml", "json"],
extract_iocs=True,
map_to_mitre=True
)
# Process cybersecurity sources
sources = [
"threat_report.pdf",
"https://security-blog.com/rss",
"vulnerability_data.json"
]
cyber_knowledge = cyber_processor.build_threat_intelligence(sources)
# Generate STIX bundles
stix_bundle = cyber_knowledge.to_stix()
print(f"Generated STIX bundle with {len(stix_bundle.objects)} objects")
**Biomedical Literature Processing**
.. code-block:: python
from semanticore.domains.biomedical import BiomedicalProcessor
# Initialize biomedical processor
bio_processor = BiomedicalProcessor(
pubmed_integration=True,
extract_drug_interactions=True,
map_to_mesh=True,
clinical_trial_detection=True
)
# Process biomedical literature
sources = [
"research_papers/",
"https://pubmed.ncbi.nlm.nih.gov/rss/",
"clinical_reports.pdf"
]
biomedical_knowledge = bio_processor.build_medical_knowledge_base(sources)
# Generate medical ontology
medical_ontology = biomedical_knowledge.generate_ontology()
**Financial Data Analysis**
.. code-block:: python
from semanticore.domains.finance import FinancialProcessor
# Initialize financial processor
finance_processor = FinancialProcessor(
sec_filings=True,
news_sentiment=True,
market_data_integration=True,
regulatory_compliance=True
)
# Process financial data sources
sources = [
"earnings_reports/",
"https://feeds.finance.yahoo.com/rss/",
"sec_filings.xml"
]
financial_knowledge = finance_processor.build_financial_knowledge_graph(sources)
# Generate financial semantic triples
triples = financial_knowledge.extract_financial_triples()
Integration Examples
--------------------
**LangChain Integration**
.. code-block:: python
from langchain.llms import OpenAI
from langchain.chains import LLMChain
from semanticore.integrations.langchain import SemantiCoreLoader
# Initialize LangChain components
llm = OpenAI(temperature=0)
chain = LLMChain(llm=llm, prompt=prompt)
# Use SemantiCore as a document loader
loader = SemantiCoreLoader(
sources=["documents/"],
extract_semantics=True,
generate_triples=True
)
documents = loader.load()
# Process with LangChain
for doc in documents:
result = chain.run(doc.page_content)
print(f"Analysis: {result}")
**Streamlit Web Application**
.. code-block:: python
import streamlit as st
from semanticore import SemantiCore
st.title("SemantiCore Document Processor")
# File upload
uploaded_file = st.file_uploader("Choose a file", type=['pdf', 'docx', 'txt'])
if uploaded_file is not None:
# Initialize SemantiCore
core = SemantiCore()
# Process the file
with st.spinner("Processing document..."):
result = core.process_document(uploaded_file)
# Display results
st.success("Processing complete!")
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Entities", len(result.entities))
with col2:
st.metric("Triples", len(result.triples))
with col3:
st.metric("Embeddings", len(result.embeddings))
# Show entities
st.subheader("Extracted Entities")
for entity in result.entities[:10]:
st.write(f"{entity.text} ({entity.type})")
Performance Optimization Examples
--------------------------------
**Batch Processing for Large Datasets**
.. code-block:: python
from semanticore import SemantiCore
import concurrent.futures
# Initialize SemantiCore with optimized settings
core = SemantiCore(
config={
"processing": {
"batch_size": 100,
"max_workers": 8,
"timeout": 600,
"memory_limit": "8GB"
}
}
)
# Process large dataset in batches
documents = load_large_dataset() # 10,000+ documents
def process_batch(batch):
return core.process_documents(batch)
# Split into batches
batch_size = 100
batches = [documents[i:i + batch_size] for i in range(0, len(documents), batch_size)]
# Process batches in parallel
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
results = list(executor.map(process_batch, batches))
print(f"Processed {len(documents)} documents in {len(batches)} batches")
**Memory-Efficient Processing**
.. code-block:: python
from semanticore import SemantiCore
import gc
# Initialize with memory optimization
core = SemantiCore(
config={
"processing": {
"batch_size": 50,
"max_workers": 2,
"memory_limit": "4GB",
"cleanup_interval": 10
}
}
)
# Process documents with memory management
documents = load_documents()
for i, doc in enumerate(documents):
# Process single document
result = core.process_document(doc)
# Store results
store_results(result)
# Clean up memory periodically
if i % 10 == 0:
gc.collect()
print(f"Processed {i} documents, memory cleaned")
.. raw:: html
<div style="text-align: center; margin: 20px 0; padding: 15px; background-color: #f0f8ff; border-left: 4px solid #27AE60; border-radius: 5px;">
<strong>💡 Tip:</strong> These examples can be combined and customized for your specific use case. Check the API reference for more detailed parameter options.
</div>
+286
View File
@@ -0,0 +1,286 @@
Getting Started with SemantiCore
================================
Welcome to SemantiCore! This guide will help you get up and running with the most comprehensive semantic data transformation toolkit.
Installation
------------
Choose the installation option that best fits your needs:
**Complete Installation (Recommended)**
.. code-block:: bash
pip install "semanticore[all]"
**Lightweight Installation**
.. code-block:: bash
pip install semanticore
**Specific Format Support**
.. code-block:: bash
# PDF and Office documents
pip install "semanticore[pdf,office]"
# Web content and feeds
pip install "semanticore[web,feeds]"
# Database and vector stores
pip install "semanticore[database,vector]"
# Machine learning capabilities
pip install "semanticore[ml]"
**Development Installation**
.. code-block:: bash
git clone https://github.com/semanticore/semanticore.git
cd semanticore
pip install -e ".[dev]"
Quick Start
-----------
**30-Second Demo: From Any Format to Knowledge**
.. code-block:: python
from semanticore import SemantiCore
# Initialize with preferred providers
core = SemantiCore(
llm_provider="openai",
embedding_model="text-embedding-3-large",
vector_store="pinecone",
graph_db="neo4j"
)
# Process ANY data format
sources = [
"financial_report.pdf",
"https://example.com/news/rss",
"research_papers/",
"data.json",
"https://example.com/article"
]
# One-line semantic transformation
knowledge_base = core.build_knowledge_base(sources)
print(f"Processed {len(knowledge_base.documents)} documents")
print(f"Extracted {len(knowledge_base.entities)} entities")
print(f"Generated {len(knowledge_base.triples)} semantic triples")
print(f"Created {len(knowledge_base.embeddings)} vector embeddings")
# Query the knowledge base
results = knowledge_base.query("What are the key financial trends?")
Basic Usage Examples
--------------------
**1. Document Processing**
.. code-block:: python
from semanticore.processors import DocumentProcessor
# Initialize document processor
doc_processor = DocumentProcessor(
extract_tables=True,
extract_images=True,
extract_metadata=True,
preserve_structure=True
)
# Process various document types
pdf_content = doc_processor.process_pdf("report.pdf")
docx_content = doc_processor.process_docx("document.docx")
pptx_content = doc_processor.process_pptx("presentation.pptx")
**2. Web Content Processing**
.. code-block:: python
from semanticore.processors import WebProcessor, FeedProcessor
# Web content processor
web_processor = WebProcessor(
respect_robots=True,
extract_metadata=True,
follow_redirects=True,
max_depth=3
)
# RSS/Atom feed processor
feed_processor = FeedProcessor(
update_interval="5m",
deduplicate=True,
extract_full_content=True
)
# Process web content
webpage = web_processor.process_url("https://example.com/article")
semantics = core.extract_semantics(webpage.content)
**3. Semantic Extraction**
.. code-block:: python
from semanticore.extraction import TripleExtractor
# Initialize triple extractor
triple_extractor = TripleExtractor(
confidence_threshold=0.8,
include_implicit_relations=True,
temporal_modeling=True
)
# Extract triples from any content
text = "Apple Inc. was founded by Steve Jobs in 1976 in Cupertino, California."
triples = triple_extractor.extract_triples(text)
print(triples)
# [
# Triple(subject="Apple Inc.", predicate="founded_by", object="Steve Jobs"),
# Triple(subject="Apple Inc.", predicate="founded_in", object="1976"),
# Triple(subject="Apple Inc.", predicate="located_in", object="Cupertino"),
# Triple(subject="Cupertino", predicate="located_in", object="California")
# ]
**4. Knowledge Graph Construction**
.. code-block:: python
from semanticore.knowledge_graph import KnowledgeGraphBuilder
# Initialize knowledge graph builder
kg_builder = KnowledgeGraphBuilder(
storage_backend="neo4j",
uri="bolt://localhost:7687",
username="neo4j",
password="password"
)
# Build knowledge graph from triples
kg_builder.add_triples(triples)
kg_builder.build()
# Query the knowledge graph
results = kg_builder.query("""
MATCH (e:Entity {name: "Apple Inc."})
RETURN e
""")
**5. Vector Embeddings**
.. code-block:: python
from semanticore.embeddings import SemanticEmbedder
# Initialize semantic embedder
embedder = SemanticEmbedder(
model="text-embedding-3-large",
dimension=1536,
preserve_context=True,
semantic_chunking=True
)
# Generate semantic embeddings
documents = load_documents()
semantic_chunks = embedder.semantic_chunk(documents)
embeddings = embedder.generate_embeddings(semantic_chunks)
# Store in vector database
vector_store = core.get_vector_store("pinecone")
vector_store.store_embeddings(semantic_chunks, embeddings)
# Semantic search
query = "artificial intelligence applications in healthcare"
results = vector_store.semantic_search(query, top_k=10)
Configuration
-------------
SemantiCore can be configured through environment variables or a configuration file:
**Environment Variables**
.. code-block:: bash
export SEMANTICORE_LLM_PROVIDER=openai
export SEMANTICORE_EMBEDDING_MODEL=text-embedding-3-large
export SEMANTICORE_VECTOR_STORE=pinecone
export SEMANTICORE_GRAPH_DB=neo4j
export OPENAI_API_KEY=your_openai_api_key
export PINECONE_API_KEY=your_pinecone_api_key
**Configuration File (config.yaml)**
.. code-block:: yaml
llm:
provider: openai
model: gpt-4
api_key: ${OPENAI_API_KEY}
embeddings:
model: text-embedding-3-large
dimension: 1536
preserve_context: true
vector_store:
provider: pinecone
api_key: ${PINECONE_API_KEY}
environment: us-west1-gcp
knowledge_graph:
provider: neo4j
uri: bolt://localhost:7687
username: neo4j
password: password
processing:
batch_size: 100
max_workers: 4
timeout: 300
Next Steps
----------
Now that you have SemantiCore installed and running, explore these resources:
* :doc:`examples` - Comprehensive examples for different use cases
* :doc:`tutorials/index` - Step-by-step tutorials
* :doc:`api/index` - Complete API reference
* :doc:`advanced/streaming` - Real-time processing capabilities
* :doc:`advanced/deployment` - Production deployment guide
Common Issues
-------------
**Import Error: No module named 'semanticore'**
Make sure you've installed SemantiCore correctly. Try reinstalling with:
.. code-block:: bash
pip install --upgrade semanticore
**API Key Errors**
Ensure your API keys are set correctly in environment variables or configuration file.
**Memory Issues**
For large documents, consider increasing your system's memory or using batch processing.
**Performance Issues**
Enable GPU acceleration if available and adjust batch sizes in configuration.
Need Help?
----------
* 📖 **Documentation**: Browse the complete documentation
* 💬 **Discord**: Join our community for real-time support
* 🐙 **GitHub**: Report issues and contribute
* 📧 **Email**: Contact us at support@semanticore.io
.. raw:: html
<div style="text-align: center; margin: 20px 0; padding: 15px; background-color: #e8f4fd; border-left: 4px solid #2980B9; border-radius: 5px;">
<strong>💡 Pro Tip:</strong> Start with the lightweight installation and add specific format support as needed. This keeps your environment clean and reduces dependencies.
BIN
View File
Binary file not shown.
+35
View File
@@ -0,0 +1,35 @@
# Documentation dependencies for SemantiCore
# Core Sphinx
sphinx>=7.0.0
sphinx-rtd-theme>=1.3.0
# Sphinx extensions
sphinx-copybutton>=0.5.0
sphinx-tabs>=3.4.0
myst-parser>=2.0.0
sphinxcontrib-spelling>=8.0.0
# Documentation quality tools
doc8>=1.1.0
sphinx-lint>=0.6.0
# Additional extensions
sphinx-autodoc-typehints>=1.24.0
sphinx-autobuild>=2021.3.14
sphinx-gallery>=0.15.0
# For PDF generation
sphinx-latex-parser>=0.1.0
# For better code highlighting
pygments>=2.15.0
# For spell checking
pyenchant>=3.2.0
# For link checking
requests>=2.31.0
# For development
watchdog>=3.0.0
+362
View File
@@ -0,0 +1,362 @@
Quick Start Tutorial
===================
This tutorial will guide you through your first steps with SemantiCore, from installation to processing your first document.
Prerequisites
-------------
- Python 3.8 or higher
- pip package manager
- Basic knowledge of Python
Installation
------------
**Step 1: Install SemantiCore**
.. code-block:: bash
# Complete installation with all features
pip install "semanticore[all]"
# Or lightweight installation
pip install semanticore
**Step 2: Verify Installation**
.. code-block:: python
import semanticore
print(f"SemantiCore version: {semanticore.__version__}")
Your First Document
-------------------
**Step 1: Create a Sample Document**
Create a file named `sample.txt` with the following content:
.. code-block:: text
Apple Inc. was founded by Steve Jobs and Steve Wozniak in 1976.
The company is headquartered in Cupertino, California.
Tim Cook became CEO in 2011 after Steve Jobs passed away.
Apple's revenue in 2023 was $394.33 billion.
**Step 2: Process the Document**
.. code-block:: python
from semanticore import SemantiCore
# Initialize SemantiCore
core = SemantiCore()
# Process the document
result = core.process_document("sample.txt")
# View results
print(f"Entities found: {len(result.entities)}")
print(f"Triples generated: {len(result.triples)}")
print(f"Embeddings created: {len(result.embeddings)}")
**Step 3: Explore the Results**
.. code-block:: python
# View extracted entities
for entity in result.entities:
print(f"Entity: {entity.text} (Type: {entity.type})")
# View generated triples
for triple in result.triples:
print(f"Triple: {triple.subject} | {triple.predicate} | {triple.object}")
# View embeddings
print(f"Embedding dimension: {len(result.embeddings[0])}")
Working with Different Formats
------------------------------
**PDF Documents**
.. code-block:: python
from semanticore.processors import DocumentProcessor
# Initialize PDF processor
pdf_processor = DocumentProcessor()
# Process PDF
pdf_result = pdf_processor.process_pdf("document.pdf")
print(f"Extracted text: {len(pdf_result.text)} characters")
**Web Content**
.. code-block:: python
from semanticore.processors import WebProcessor
# Initialize web processor
web_processor = WebProcessor()
# Process web page
web_result = web_processor.process_url("https://example.com/article")
print(f"Title: {web_result.title}")
print(f"Content: {len(web_result.content)} characters")
**Structured Data**
.. code-block:: python
from semanticore.processors import StructuredDataProcessor
# Initialize structured data processor
structured_processor = StructuredDataProcessor()
# Process JSON data
json_result = structured_processor.process_json("data.json")
print(f"Schema: {json_result.schema}")
Building a Knowledge Graph
--------------------------
**Step 1: Initialize Knowledge Graph**
.. code-block:: python
from semanticore.knowledge_graph import KnowledgeGraphBuilder
# Initialize knowledge graph builder
kg_builder = KnowledgeGraphBuilder(
storage_backend="memory" # Use in-memory storage for this tutorial
)
**Step 2: Add Triples**
.. code-block:: python
# Add triples from processed document
for triple in result.triples:
kg_builder.add_triple(
subject=triple.subject,
predicate=triple.predicate,
object=triple.object
)
**Step 3: Build and Query**
.. code-block:: python
# Build the knowledge graph
kg_builder.build()
# Query the knowledge graph
query_results = kg_builder.query("""
MATCH (e:Entity {name: "Apple Inc."})
RETURN e
""")
print(f"Query results: {len(query_results)}")
Creating Vector Embeddings
--------------------------
**Step 1: Initialize Embedder**
.. code-block:: python
from semanticore.embeddings import SemanticEmbedder
# Initialize semantic embedder
embedder = SemanticEmbedder(
model="text-embedding-3-large",
dimension=1536
)
**Step 2: Generate Embeddings**
.. code-block:: python
# Generate embeddings for document chunks
chunks = result.chunks
embeddings = embedder.generate_embeddings(chunks)
print(f"Generated {len(embeddings)} embeddings")
print(f"Each embedding has {len(embeddings[0])} dimensions")
**Step 3: Semantic Search**
.. code-block:: python
# Perform semantic search
query = "Who founded Apple?"
search_results = embedder.semantic_search(query, embeddings, top_k=3)
for i, (chunk, score) in enumerate(search_results):
print(f"{i+1}. Score: {score:.3f}")
print(f" Content: {chunk[:100]}...")
Real-Time Processing
--------------------
**Step 1: Set up Feed Processing**
.. code-block:: python
from semanticore.streaming import FeedProcessor
import asyncio
async def process_feeds():
# Initialize feed processor
feed_processor = FeedProcessor(
update_interval="5m",
deduplicate=True
)
# Subscribe to a feed
feed_processor.subscribe("https://feeds.feedburner.com/TechCrunch")
# Process items
async for item in feed_processor.stream():
print(f"New item: {item.title}")
# Process with SemantiCore
item_result = core.process_document(item.content)
print(f"Extracted {len(item_result.entities)} entities")
# Run the feed processor
asyncio.run(process_feeds())
Configuration
-------------
**Environment Variables**
.. code-block:: bash
export SEMANTICORE_LLM_PROVIDER=openai
export SEMANTICORE_EMBEDDING_MODEL=text-embedding-3-large
export OPENAI_API_KEY=your_api_key_here
**Configuration File**
Create `config.yaml`:
.. code-block:: yaml
llm:
provider: openai
model: gpt-4
api_key: ${OPENAI_API_KEY}
embeddings:
model: text-embedding-3-large
dimension: 1536
processing:
batch_size: 100
max_workers: 4
**Programmatic Configuration**
.. code-block:: python
config = {
"llm": {
"provider": "openai",
"model": "gpt-4",
"api_key": "your_api_key"
},
"embeddings": {
"model": "text-embedding-3-large",
"dimension": 1536
}
}
core = SemantiCore(config=config)
Error Handling
--------------
**Basic Error Handling**
.. code-block:: python
from semanticore.core.exceptions import SemantiCoreError
try:
result = core.process_document("document.pdf")
except SemantiCoreError as e:
print(f"Error processing document: {e}")
except FileNotFoundError:
print("Document not found")
except Exception as e:
print(f"Unexpected error: {e}")
**Validation**
.. code-block:: python
# Validate input before processing
import os
def process_safe(file_path):
if not os.path.exists(file_path):
raise FileNotFoundError(f"File not found: {file_path}")
if os.path.getsize(file_path) > 100 * 1024 * 1024: # 100MB
raise ValueError("File too large")
return core.process_document(file_path)
Performance Optimization
------------------------
**Batch Processing**
.. code-block:: python
# Process multiple documents efficiently
documents = ["doc1.pdf", "doc2.pdf", "doc3.pdf"]
results = core.process_documents(documents)
for doc, result in zip(documents, results):
print(f"{doc}: {len(result.entities)} entities")
**Memory Management**
.. code-block:: python
# Process large datasets with generators
def document_generator():
for doc in large_dataset:
yield doc
for result in core.process_documents_stream(document_generator()):
process_result(result)
Next Steps
----------
Congratulations! You've completed the quick start tutorial. Here's what you can explore next:
1. **Advanced Examples**: Check out the comprehensive examples in the examples section
2. **API Reference**: Explore the complete API documentation
3. **Tutorials**: Follow step-by-step tutorials for specific use cases
4. **Community**: Join our Discord community for help and discussions
**Additional Resources**
- 📖 [Complete Documentation](https://semanticore.readthedocs.io/)
- 💡 [Examples Repository](https://github.com/semanticore/examples)
- 💬 [Community Discord](https://discord.gg/semanticore)
- 🐙 [GitHub Repository](https://github.com/semanticore/semanticore)
.. raw:: html
<div style="text-align: center; margin: 20px 0; padding: 15px; background-color: #d4edda; border-left: 4px solid #27AE60; border-radius: 5px;">
<strong>🎉 Congratulations!</strong> You've successfully completed the SemantiCore quick start tutorial. You're now ready to transform your data into intelligent knowledge!
</div>
+179
View File
@@ -0,0 +1,179 @@
#!/usr/bin/env python3
"""
Script to build SemantiCore documentation.
"""
import os
import sys
import subprocess
import shutil
from pathlib import Path
def run_command(command, cwd=None):
"""Run a shell command and return the result."""
try:
result = subprocess.run(
command,
shell=True,
cwd=cwd,
capture_output=True,
text=True,
check=True
)
print(f"{command}")
return result.stdout
except subprocess.CalledProcessError as e:
print(f"{command}")
print(f"Error: {e.stderr}")
return None
def install_dependencies():
"""Install documentation dependencies."""
print("📦 Installing documentation dependencies...")
dependencies = [
"sphinx",
"sphinx-rtd-theme",
"sphinx-copybutton",
"sphinx-tabs",
"myst-parser",
"sphinxcontrib-spelling",
"doc8",
"sphinx-lint"
]
for dep in dependencies:
run_command(f"pip install {dep}")
def build_documentation():
"""Build the documentation."""
print("🔨 Building documentation...")
docs_dir = Path("docs")
if not docs_dir.exists():
print("❌ docs directory not found!")
return False
# Change to docs directory
os.chdir(docs_dir)
# Clean previous builds
if Path("_build").exists():
shutil.rmtree("_build")
# Build HTML documentation
result = run_command("make html")
if result is None:
return False
# Check for broken links
print("🔗 Checking for broken links...")
result = run_command("make linkcheck")
if result is None:
print("⚠️ Link check failed, but continuing...")
# Run doctests
print("🧪 Running doctests...")
result = run_command("make doctest")
if result is None:
print("⚠️ Doctests failed, but continuing...")
return True
def serve_documentation():
"""Serve the documentation locally."""
print("🌐 Starting local documentation server...")
docs_dir = Path("docs")
build_dir = docs_dir / "_build" / "html"
if not build_dir.exists():
print("❌ Documentation not built. Run build first.")
return False
os.chdir(build_dir)
print("📖 Documentation available at: http://localhost:8000")
print("Press Ctrl+C to stop the server.")
try:
run_command("python -m http.server 8000")
except KeyboardInterrupt:
print("\n🛑 Server stopped.")
return True
def deploy_documentation():
"""Deploy documentation to GitHub Pages."""
print("🚀 Deploying documentation to GitHub Pages...")
# Check if we're on the main branch
result = run_command("git branch --show-current")
if result and "main" not in result.strip():
print("❌ Not on main branch. Deployment only works from main.")
return False
# Build documentation
if not build_documentation():
return False
# Deploy to gh-pages branch
docs_dir = Path("docs")
build_dir = docs_dir / "_build" / "html"
if not build_dir.exists():
print("❌ Documentation not built.")
return False
# Create gh-pages branch if it doesn't exist
run_command("git checkout --orphan gh-pages || git checkout gh-pages")
# Copy built documentation
for item in build_dir.iterdir():
if item.is_file():
shutil.copy2(item, ".")
elif item.is_dir():
shutil.copytree(item, item.name, dirs_exist_ok=True)
# Commit and push
run_command("git add .")
run_command('git commit -m "Update documentation"')
run_command("git push origin gh-pages")
# Switch back to main branch
run_command("git checkout main")
print("✅ Documentation deployed successfully!")
return True
def main():
"""Main function."""
if len(sys.argv) < 2:
print("Usage: python build_docs.py [install|build|serve|deploy|all]")
print("\nCommands:")
print(" install - Install documentation dependencies")
print(" build - Build documentation")
print(" serve - Serve documentation locally")
print(" deploy - Deploy to GitHub Pages")
print(" all - Install, build, and serve")
return
command = sys.argv[1].lower()
if command == "install":
install_dependencies()
elif command == "build":
build_documentation()
elif command == "serve":
serve_documentation()
elif command == "deploy":
deploy_documentation()
elif command == "all":
install_dependencies()
if build_documentation():
serve_documentation()
else:
print(f"❌ Unknown command: {command}")
if __name__ == "__main__":
main()