two species similarity checker
h1 {
color: #333;
}
.container {
margin-top: 20px;
}
.compare-button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
margin-top: 20px;
}
.compare-button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 5px;
}
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.highlight {
background-color: #f8d7da;
color: #721c24;
}
.no-difference {
color: green;
}
.key {
margin-top: 30px;
padding: 15px;
background-color: #e7f3fe;
border-radius: 5px;
border: 1px solid #b8daff;
}
.key ol {
margin-left: 20px;
}
Compare
function compareParagraphs() {
let para1 = document.getElementById("para1").value.trim();
let para2 = document.getElementById("para2").value.trim();
if (para1 && para2) {
// Define keywords related to plant features
const plantFeatures = [
"Habit", "tall", "Leaf", "Petiole", "Inflorescences", "Flower", "calyx", "corolla",
"Anthers", "ovary", "Fruit", "Berry", "Seeds", "Fl. & Fr."
];
// Function to extract relevant feature from text
const extractFeature = (para, feature) => {
const regex = new RegExp(`(${feature}[^\\.]*\\.)`, "i");
const match = para.match(regex);
return match ? match[0].trim() : "Not Available";
};
// Function to compare two paragraphs based on features
const compareFeatures = (para1, para2, features) => {
let comparison = [];
features.forEach(feature => {
let para1Feature = extractFeature(para1, feature);
let para2Feature = extractFeature(para2, feature);
let difference = para1Feature !== para2Feature;
comparison.push({
feature: feature,
para1: para1Feature,
para2: para2Feature,
difference: difference
});
});
return comparison;
};
// Generate a Taxonomy-style Dichotomous Key
const generateDichotomousKey = (comparison) => {
let key = '
";
// Generate and display the dichotomous key
const dichotomousKeyHTML = generateDichotomousKey(comparisonResult);
// Show the results and the dichotomous key
document.getElementById("result").innerHTML = resultHTML + `
Compare
Taxonomic Dichotomous Key
- ';
comparison.forEach((item, index) => {
if (item.difference) {
// Questions for the key based on feature differences
key += `
- The plants differ in ${item.feature}
`; key += `${item.para1} Plant 1:
${item.para2} Plant 2:
`; } }); key += '
No significant differences found to build a dichotomous key.
"; }; // Compare the paragraphs const comparisonResult = compareFeatures(para1, para2, plantFeatures); // Display the results in a table let resultHTML = 'Comparison Results
| Feature | Paragraph 1 | Paragraph 2 | Difference |
|---|---|---|---|
| ${item.feature} | ${item.para1} | ${item.para2} | ${diff} |
${dichotomousKeyHTML}
`;
} else {
alert("Please enter both paragraphs to compare.");
}
}