Skip to content

9cog/cogpwsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

CogPwsh - OpenCog in PowerShell

A pure PowerShell implementation of OpenCog's core cognitive architecture for AI and knowledge representation.

🧠 What is This?

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

✨ Key Features

Core Components

  1. Atoms - Fundamental units of knowledge

    • Nodes: Concepts, predicates, variables
    • Links: Relationships connecting atoms
    • Truth Values: Probabilistic strength and confidence
  2. AtomSpace - Hypergraph knowledge base

    • Efficient storage and indexing
    • Quick lookups by type, name, relationships
    • Incoming/outgoing set navigation
  3. Pattern Matcher - Query engine

    • Variable binding and unification
    • Pattern-based queries
    • Complex query construction

πŸš€ Quick Start

# 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
}

πŸ“š Documentation

Module Structure

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

Examples

Building a Taxonomy

$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"
}

Properties with Predicates

$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)

Truth Values

# 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
}

πŸ§ͺ Testing

Run the comprehensive test suite:

cd OpenCog/Tests
./OpenCog.Tests.ps1

Expected: 58+ tests passing

Run examples:

cd OpenCog/Examples
./QuickDemo.ps1          # Quick demonstration
./BasicUsage.ps1         # Comprehensive examples
./KnowledgeGraph.ps1     # Advanced knowledge graphs

πŸ“– API Reference

Atom Creation

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

AtomSpace Operations

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

Pattern Matching

Function Description
Find-Pattern Find pattern matches
Find-AtomsByPredicate Find with predicate
Invoke-Query Execute query
New-QueryBuilder Create query builder

🎯 Use Cases

  • 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

πŸ”¬ Technical Details

  • Language: Pure PowerShell 5.1+
  • Dependencies: None
  • Platforms: Windows, Linux, macOS
  • Performance: O(1) lookups, O(n) pattern matching
  • Architecture: Hypergraph with multiple indexes

🀝 Contributing

Contributions welcome! Areas for enhancement:

  1. Additional atom types and link types
  2. Performance optimizations
  3. Persistence backends (JSON, SQLite, etc.)
  4. Probabilistic Logic Networks (PLN)
  5. More examples and documentation

πŸ“„ License

MIT License - See LICENSE file

πŸ”— Related Projects

πŸ™ Acknowledgments

  • OpenCog Foundation for the cognitive architecture design
  • PowerShell team for the excellent platform
  • Community contributors

πŸ“§ Contact


Bringing cognitive computing to PowerShell 🧠⚑

What's Next?

The OpenCog/ directory contains a complete, functional implementation of OpenCog in PowerShell. This coexists with the existing PowerShellForGitHub code in the repository.

Project Structure

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.

About

cognitive powershell

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors