Class: SwarmMemory::Core::MetadataExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_memory/core/metadata_extractor.rb

Overview

Extracts structured metadata from memory entries

This class wraps FrontmatterParser and provides additional metadata extraction logic specific to the memory system.

Class Method Summary collapse

Class Method Details

.extract(content) ⇒ Hash

Extract all metadata from a memory entry

Examples:

 = MetadataExtractor.extract(content)
[:confidence] # => "high"
[:type] # => "concept"
[:tags] # => ["ruby", "testing"]

Parameters:

  • content (String)

    Full entry content

Returns:

  • (Hash)

    Extracted metadata



21
22
23
# File 'lib/swarm_memory/core/metadata_extractor.rb', line 21

def extract(content)
  FrontmatterParser.(content)
end

.has_required_frontmatter?(content) ⇒ Boolean

Check if entry has required frontmatter for quality

Parameters:

  • content (String)

    Full entry content

Returns:

  • (Boolean)

    True if entry has basic required fields



29
30
31
32
# File 'lib/swarm_memory/core/metadata_extractor.rb', line 29

def has_required_frontmatter?(content)
   = extract(content)
  ![:type].nil? && ![:confidence].nil?
end

.quality_score(content) ⇒ Integer

Calculate entry quality score (0-100)

Parameters:

  • content (String)

    Full entry content

Returns:

  • (Integer)

    Quality score



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/swarm_memory/core/metadata_extractor.rb', line 38

def quality_score(content)
   = extract(content)
  score = 0

  # Has type (20 points)
  score += 20 if [:type]

  # Has confidence (20 points)
  score += 20 if [:confidence]

  # Has tags (15 points)
  score += 15 unless [:tags].empty?

  # Has related links (15 points)
  score += 15 unless [:related].empty?

  # Has domain (10 points)
  score += 10 if [:domain]

  # Has last_verified (10 points)
  score += 10 if [:last_verified]

  # High confidence bonus (10 points)
  score += 10 if [:confidence] == "high"

  score
end