Giter Club home page Giter Club logo

Comments (4)

spencermountain avatar spencermountain commented on June 9, 2024

from compromise.

MarketingPip avatar MarketingPip commented on June 9, 2024

@spencermountain - I have already seen this. I know it goes through that plus LZMA. But I didn't know if it when further with JSON-Schema Key Compression. Again - please re-look over my suggestions. (I have previously played with your compression library month's prior & something similar to increase compression even further)

from compromise.

MarketingPip avatar MarketingPip commented on June 9, 2024

@spencermountain - not trying to piss you off. But please see below.

function compressLexicon(lexicon) {
  const compressedLexicon = {};
  const tagMap = {}; // Map for tracking assigned numbers for each tag
  let tagCounter = 1; // Counter for assigning numbers to tags
  const tagSchema = {}; // JSON schema for tag values

  for (const word in lexicon) {
    const tag = lexicon[word];
    if (Array.isArray(tag)) {
      const compressedTags = [];
      for (const t of tag) {
        if (!tagMap.hasOwnProperty(t)) {
          // Assign a new number to the tag
          tagMap[t] = `Key${tagCounter}`;
          tagSchema[tagMap[t]] = t; // Store original tag value
          tagCounter++;
        }
        compressedTags.push(tagMap[t]);
      }
      compressedLexicon[word] = compressedTags;
    } else {
      if (!tagMap.hasOwnProperty(tag)) {
        // Assign a new number to the tag
        tagMap[tag] = `Key${tagCounter}`;
        tagSchema[tagMap[tag]] = tag; // Store original tag value
        tagCounter++;
      }
      compressedLexicon[word] = tagMap[tag];
    }
  }

  return { compressedLexicon, tagSchema };
}

function decompressLexicon(compressedLexicon, tagSchema) {
  const decompressedLexicon = {};

  for (const word in compressedLexicon) {
    const tag = compressedLexicon[word];
    if (Array.isArray(tag)) {
      const decompressedTags = [];
      for (const t of tag) {
        decompressedTags.push(tagSchema[t] || t);
      }
      decompressedLexicon[word] = decompressedTags;
    } else {
      decompressedLexicon[word] = tagSchema[tag] || tag;
    }
  }

  return decompressedLexicon;
}

// Example lexicon
const originalLexicon = {
  House: ['#Noun'],
  apple: "Fruit",
  toronto: "#Noun",
  "house of": "#Noun",
  
  Hello: ['#Verb'],
};

// Compress the lexicon
const { compressedLexicon, tagSchema } = compressLexicon(originalLexicon);
console.log("Compressed Lexicon:", compressedLexicon);
console.log("Tag Schema:", tagSchema);

// Decompress the lexicon
const decompressedLexicon = decompressLexicon(compressedLexicon, tagSchema);
console.log("Decompressed Lexicon:", decompressedLexicon);

Then apply efrt & LZMA.

from compromise.

MarketingPip avatar MarketingPip commented on June 9, 2024

@spencermountain - don't mean to mention / blow your issues again. But I refered / thought the above might be a good approach for doing / using these rules

from compromise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.