Replies: 2 comments
-
|
hi sabelaV, i think you are creating a nested structure in your plugin, when you are doing reduces inside the |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Hi spencermountain, thank you for your answer, but I´ve changed my code following your suggestion and it still doen´t work properly. It takes apart each noun of multi-words.
I will appreciate very much your help. I think your plugin is awesome, but I need multi words working. Thanks in advance. Kind Regards.
const myPlugin = {
tags: {
Producto: { isA: 'Noun' },
ProductoCompuesto: { isA: 'multi-word' },
Comunidad: { isA: 'Noun' },
ComunidadCompuesto: { isA: 'multi-word' },
Provincia: { isA: 'Noun' },
ProvinciaCompuesto: { isA: 'multi-word' },
Provincia: { isA: 'Noun' },
Anyo: { isA: 'Value' }
},
words: {
...Object.fromEntries(productos.simples.map(prod => [prod.toLowerCase(), 'Producto'])),
...Object.fromEntries(productos.compuestos.map(prod => [prod.toLowerCase(), 'ProductoCompuesto'])),
...Object.fromEntries(comunidades.simples.map(com => [com.toLowerCase(), 'Comunidad'])),
...Object.fromEntries(comunidades.compuestos.map(com => [com.toLowerCase(), 'ComunidadCompuesto'])),
...Object.fromEntries(provincias.simples.map(prov => [prov.toLowerCase(), 'Provincia'])),
...Object.fromEntries(provincias.compuestos.map(prov => [prov.toLowerCase(), 'ProvinciaCompuesto'])),
...Object.fromEntries(data.Anyos.map(ay => [ay.toString(), 'Anyo']))
}
};
try {
nlp.plugin(myPlugin);
const input = document.getElementById('input-text').value;
const doc = nlp(input.toLowerCase());
console.log(doc.debug());
console.log(doc.match('#Producto').out('array'));
// Obtener coincidencias
const resultado = {
Producto: doc.match('#Producto').out('array'),
ProductosCompuestos: doc.match('#ProductoCompuesto').out('array'),
Comunidad: doc.match('#Comunidad').out('array'),
ComunidadesCompuestas: doc.match('#ComunidadCompuesto').out('array'),
Provincia: doc.match('#Provincia').out('array'),
ProvinciasCompuestas: doc.match('#ProvinciaCompuesto').out('array'),
Anyo: doc.match('#Anyo').out('array')
};
console.log("Resultado:", resultado);
document.getElementById('output').innerText = JSON.stringify(resultado, null, 2);
} catch (error) {
console.error("Error al analizar texto:", error);
document.getElementById('output').innerText = "Error al analizar el texto.";
}
}
…________________________________
De: spencer kelly ***@***.***>
Enviado: jueves, 14 de noviembre de 2024 16:32
Para: spencermountain/compromise ***@***.***>
Cc: sabelaV ***@***.***>; Author ***@***.***>
Asunto: Re: [spencermountain/compromise] Adding multi-words to the compromise lexicon for a 'natural language data filter' (Discussion #1157)
hi sabelaV, i think you are creating a nested structure in your plugin, when you are doing reduces inside the words property.
That should be a flat list of 'word':'Tag'.
cheers
—
Reply to this email directly, view it on GitHub<#1157 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AS446UIA2L6TKAG5RYBGVVD2AS7BJAVCNFSM6AAAAABRZE33DCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMRVGYZDCOI>.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have new words for the lexicon that are multi-words, I already have separated words and multi-words in different arrays. For example: comunidades.compuestos (10) ['Principado de Asturias', 'Illes Balears', 'Castilla y León', 'Castilla - La Mancha', 'Comunitat Valenciana', 'Comunidad de Madrid', 'Región de Murcia', 'Comunidad Foral de Navarra', 'País Vasco', 'La Rioja']
app.netlify: https://6736147c419b8b00b9eeabb6--datafilter2024.netlify.app/
Here is my code:
// Cargar datos desde el archivo JSON
async function loadData() {
try {
const response = await fetch('data.json');
if (!response.ok) throw new Error('No se pudo cargar data.json');
const data = await response.json();
console.log("Datos cargados:", data); // Verificar que los datos se cargaron
return data;
} catch (error) {
console.error("Error al cargar datos:", error);
document.getElementById('output').innerText = "Error al cargar data.json";
return null;
}
}
// Función para separar nombres simples y compuestos
const separarNombres = (lista) => {
return {
simples: lista.filter(nombre => !nombre.includes(" ")),
compuestos: lista.filter(nombre => nombre.includes(" "))
};
};
// Configurar el plugin y analizar el texto
async function setupPluginAndAnalyze() {
const data = await loadData();
if (!data) return;
// Separar productos en nombres simples y compuestos
const productos = separarNombres(data.Productos);
const comunidades = separarNombres(data.Comunidades);
const provincias = separarNombres(data.Provincias);
console.log("productos.compuestos", productos.compuestos);
console.log("comunidades.compuestos", comunidades.compuestos);
const myPlugin = {
api: (View) => {
View.prototype.toSingular = function () {
this.match('#Noun').toSingular();
return this;
};
},
tags: {
Producto: { isA: 'Noun' },
ProductoCompuesto: { isA: 'multi-word' },
Comunidad: { isA: 'Noun' },
ComunidadCompuesto: { isA: 'multi-word' },
Provincia: { isA: 'Noun' },
ProvinciaCompuesto: { isA: 'multi-word' },
Provincia: { isA: 'Noun' },
Anyo: { isA: 'Value' }
},
words: {
...productos.simples.reduce((acc, prod) => ({ ...acc, [prod]: 'Producto' }), {}),
...productos.compuestos.reduce((acc, prod) => ({ ...acc, [prod]: 'ProductoCompuesto' }), {}),
...comunidades.simples.reduce((acc, comunidad) => ({ ...acc, [comunidad]: 'Comunidad' }), {}),
...comunidades.compuestos.reduce((acc, comunidad) => ({ ...acc, [comunidad]: 'ComunidadCompuesto' }), {}),
...provincias.simples.reduce((acc, provincia) => ({ ...acc, [provincia]: 'Provincia' }), {}),
...provincias.compuestos.reduce((acc, provincia) => ({ ...acc, [provincia]: 'ProvinciaCompuesto' }), {}),
...data.Anyos.reduce((acc, anyo) => ({ ...acc, [anyo]: 'Anyo' }), {})
}
};
try {
nlp.plugin(myPlugin);
const input = document.getElementById('input-text').value;
const doc = nlp(input);
} catch (error) {
console.error("Error al analizar texto:", error);
document.getElementById('output').innerText = "Error al analizar el texto.";
}
}
// Elementos del DOM
const inputText = document.getElementById("input-text");
const suggestionsContainer = document.getElementById("suggestions");
let loadedData = null;
// Cargar los datos y almacenarlos en una variable global
loadData().then(data => loadedData = data);
// Función para mostrar sugerencias
function showSuggestions(word) {
if (!loadedData) return;
// Filtrar las sugerencias a partir de los datos cargados
const suggestions = [
...loadedData.Productos,
...loadedData.Comunidades,
...loadedData.Provincias,
...loadedData.Anyos
].filter(suggestion => suggestion.toLowerCase().startsWith(word.toLowerCase()));
// Limpiar sugerencias anteriores
suggestionsContainer.innerHTML = "";
// Mostrar nuevas sugerencias
suggestions.forEach(suggestion => {
const suggestionElement = document.createElement("div");
suggestionElement.classList.add("suggestion");
suggestionElement.textContent = suggestion;
suggestionElement.addEventListener("click", () => {
addSuggestionToInput(suggestion);
});
suggestionsContainer.appendChild(suggestionElement);
});
// Mostrar el contenedor si hay sugerencias
suggestionsContainer.style.display = suggestions.length > 0 ? "block" : "none";
}
// Función para agregar la sugerencia al campo de texto
function addSuggestionToInput(suggestion) {
const currentText = inputText.value;
const words = currentText.split(" ");
words.pop(); // Elimina la última palabra que está siendo escrita
words.push(suggestion); // Agrega la sugerencia
inputText.value = words.join(" ") + " "; // Añade un espacio al final
// Oculta las sugerencias
suggestionsContainer.style.display = "none";
}
// Evento al escribir en el campo de texto
inputText.addEventListener("input", () => {
const currentText = inputText.value;
const words = currentText.split(" ");
const currentWord = words[words.length - 1];
// Mostrar sugerencias solo si hay una palabra en curso
if (currentWord) {
showSuggestions(currentWord);
} else {
suggestionsContainer.style.display = "none";
}
});
// Agregar el evento al botón
document.getElementById("analyze-button").addEventListener("click", setupPluginAndAnalyze);
I would want compromise recognizes "trigo blando" (the same for all multi-words) and won´t separe it in two words: "ProductosCompuestos": [
"trigo",
"blando"
], Could you help me, please!!
Beta Was this translation helpful? Give feedback.
All reactions