A pure PowerShell implementation of OpenCog's core cognitive architecture for AI and knowledge representation.
CogPwsh implements OpenCog's fundamental cognitive computing components in PowerShell, bringing advanced AI concepts to the PowerShell ecosystem:
- Hypergraph Knowledge Representation: Store knowledge as interconnected atoms
- Semantic Networks: Build complex relationships between concepts
- Pattern Matching: Query knowledge with variables and unification
- Probabilistic Reasoning: Handle uncertainty with truth values
- Pure PowerShell: No external dependencies, works cross-platform
-
Atoms - Fundamental units of knowledge
- Nodes: Concepts, predicates, variables
- Links: Relationships connecting atoms
- Truth Values: Probabilistic strength and confidence
-
AtomSpace - Hypergraph knowledge base
- Efficient storage and indexing
- Quick lookups by type, name, relationships
- Incoming/outgoing set navigation
-
Pattern Matcher - Query engine
- Variable binding and unification
- Pattern-based queries
- Complex query construction
# Import the module
Import-Module ./OpenCog/OpenCog.psd1
# Create a knowledge base
$kb = New-AtomSpace
# Create concepts
$cat = New-ConceptNode "Cat"
$animal = New-ConceptNode "Animal"
# Add to knowledge base
$cat = $kb.AddAtom($cat)
$animal = $kb.AddAtom($animal)
# Create relationship
$inheritance = New-InheritanceLink -Child $cat -Parent $animal
$kb.AddAtom($inheritance)
# Query
$concepts = $kb.GetAtomsByType('ConceptNode')
foreach ($concept in $concepts) {
Write-Host $concept.Name
}OpenCog/
βββ OpenCog.psm1 # Main module
βββ OpenCog.psd1 # Module manifest
βββ Core/
β βββ Atoms.psm1 # Atom types and factory functions
β βββ AtomSpace.psm1 # Hypergraph storage
β βββ PatternMatcher.psm1 # Query engine
βββ Examples/
β βββ QuickDemo.ps1 # Quick demonstration
β βββ BasicUsage.ps1 # Comprehensive examples
β βββ KnowledgeGraph.ps1 # Knowledge graph building
βββ Tests/
β βββ OpenCog.Tests.ps1 # Test suite
βββ README.md # Module documentation
$kb = New-AtomSpace
# Create hierarchy
$mammal = New-ConceptNode "Mammal" | ForEach-Object { $kb.AddAtom($_) }
$dog = New-ConceptNode "Dog" | ForEach-Object { $kb.AddAtom($_) }
# Link them
$link = New-InheritanceLink -Child $dog -Parent $mammal
$kb.AddAtom($link)
# Query incoming relationships
$incoming = $kb.GetIncomingSet($mammal)
foreach ($link in $incoming) {
$child = $link.GetOutgoingAtom(0)
Write-Host "$($child.Name) is a Mammal"
}$kb = New-AtomSpace
# Create predicate and concepts
$hasColor = New-PredicateNode "hasColor" | ForEach-Object { $kb.AddAtom($_) }
$apple = New-ConceptNode "Apple" | ForEach-Object { $kb.AddAtom($_) }
$red = New-ConceptNode "Red" | ForEach-Object { $kb.AddAtom($_) }
# Assert property
$eval = New-EvaluationLink -Predicate $hasColor -Arguments @($apple, $red)
$kb.AddAtom($eval)# Uncertain knowledge
$maybe = New-ConceptNode "Maybe" -Strength 0.5 -Confidence 0.6
# Certain knowledge
$certain = New-ConceptNode "Certain" -Strength 0.99 -Confidence 0.98
# Query by confidence
$allAtoms = $kb.GetAllAtoms()
$highConf = $allAtoms | Where-Object {
$_.GetTruthValue().Confidence -gt 0.9
}Run the comprehensive test suite:
cd OpenCog/Tests
./OpenCog.Tests.ps1Expected: 58+ tests passing
Run examples:
cd OpenCog/Examples
./QuickDemo.ps1 # Quick demonstration
./BasicUsage.ps1 # Comprehensive examples
./KnowledgeGraph.ps1 # Advanced knowledge graphs| Function | Description |
|---|---|
New-ConceptNode |
Create a concept node |
New-PredicateNode |
Create a predicate node |
New-VariableNode |
Create a variable for pattern matching |
New-InheritanceLink |
Create inheritance relationship |
New-SimilarityLink |
Create similarity relationship |
New-EvaluationLink |
Create predicate evaluation |
New-AndLink, New-OrLink |
Create logical relationships |
New-ImplicationLink |
Create implication |
| Function | Description |
|---|---|
New-AtomSpace |
Create new knowledge base |
Add-Atom |
Add atom to AtomSpace |
Get-Atom |
Get atom by handle |
Get-AtomsByType |
Get all atoms of type |
Get-Node |
Get node by type and name |
Get-IncomingSet |
Get incoming links |
Remove-Atom |
Remove atom |
Clear-AtomSpace |
Clear all atoms |
Get-AtomSpaceStatistics |
Get statistics |
Export-AtomSpace |
Export to JSON |
| Function | Description |
|---|---|
Find-Pattern |
Find pattern matches |
Find-AtomsByPredicate |
Find with predicate |
Invoke-Query |
Execute query |
New-QueryBuilder |
Create query builder |
- Knowledge Representation: Build semantic networks and ontologies
- AI Systems: Create intelligent reasoning systems
- Natural Language Processing: Represent linguistic knowledge
- Expert Systems: Encode domain expertise
- Research: Explore cognitive architecture concepts
- Education: Learn AI and knowledge representation
- Language: Pure PowerShell 5.1+
- Dependencies: None
- Platforms: Windows, Linux, macOS
- Performance: O(1) lookups, O(n) pattern matching
- Architecture: Hypergraph with multiple indexes
Contributions welcome! Areas for enhancement:
- Additional atom types and link types
- Performance optimizations
- Persistence backends (JSON, SQLite, etc.)
- Probabilistic Logic Networks (PLN)
- More examples and documentation
MIT License - See LICENSE file
- OpenCog: https://opencog.org - The original C++ implementation
- OpenCog Hyperon: https://github.com/trueagi-io/hyperon-experimental
- cogutil, atomspace, ure, pln: Core OpenCog C++ components
- OpenCog Foundation for the cognitive architecture design
- PowerShell team for the excellent platform
- Community contributors
- Issues: https://github.com/opencog/cogpwsh/issues
- Discussions: OpenCog mailing list
Bringing cognitive computing to PowerShell π§ β‘
The OpenCog/ directory contains a complete, functional implementation of OpenCog in PowerShell. This coexists with the existing PowerShellForGitHub code in the repository.
cogpwsh/
βββ OpenCog/ # β New OpenCog implementation
β βββ OpenCog.psm1
β βββ OpenCog.psd1
β βββ Core/
β βββ Examples/
β βββ Tests/
β βββ README.md
βββ PowerShellForGitHub.psm1 # Existing GitHub module
βββ PowerShellForGitHub.psd1
βββ GitHub*.ps1 # Existing GitHub functions
βββ README.md # This file
Both modules can coexist and be used independently.