Post Reply 
Improving the Help text on HP Prime
07-03-2024, 09:02 AM (This post was last modified: 08-29-2024 06:48 PM by ftneek.)
Post: #2
RE: Improving the Help text on HP Prime
Klass, would it be possible to upload an XML file for the current public release?

Attached is a small python script I'm using to search through the published XML file / help text, off-calculator. This can make it easy(er) to browse through search hits, and potentially notice things to improve. You should download the XML file linked in the first post, a more recent XML file would allow for more recent / relevant help text to appear in the results.

Code:
# Search for a command or phrase in the Help Catalog
# by ftneek
import xml.etree.ElementTree as ET
from typing import List, Tuple


# Load and parse the XML file with error handling
try:
    tree = ET.parse('HelpEn.xml')
    root = tree.getroot()
except ET.ParseError as e:
    print(f"Error parsing XML: {e}")
    exit(1)
except FileNotFoundError:
    print("The specified XML file was not found.")
    exit(1)


# Define a function to search for a specific feature or command
def search_feature(feature: str) -> List[Tuple[str, str, str, str, str, str]]:
    results = []
    for help_item in root.findall('HelpItem'):
        long_title = help_item.findtext('LongTitle', default="None")
        short_title = help_item.findtext('ShortTitle', default="None")
        HID = help_item.findtext('HID', default="None")
        help_text = help_item.findtext('help', default="None").strip()
        example_text = help_item.findtext('Examples', default="None").strip()

        related = ", ".join([also.text for also in help_item.findall('also') if also is not None]) or "None"

        for item in [long_title, short_title, HID, help_text, example_text]:
            if feature.lower() in item.lower():
                results.append((long_title, short_title, HID, help_text, example_text, related))
                break

    return results


def format_search_results(search_results: List[Tuple[str, str, str, str, str, str]]) -> str:
    formatted_results = []
    for long_title, short_title, HID, help_text, example_text, related in search_results:
        examples = "Example(s):" + (" " if example_text == "None" else "\n")

        formatted_results.append(
            f"HID: {HID}\n"
            f"Long Title: {long_title}\n"
            f"Short Title: {short_title}\n"
            f"{help_text}\n\n"
            f"{examples}{example_text}\n\n"
            f"See Also: {related}\n~~~~~~~"
        )
    return "\n".join(formatted_results)


if __name__ == '__main__':
    # Search for the feature
    feature_to_search = input("Search for: ").strip()
    print("~~~~~~~")
    search_results = search_feature(feature_to_search)

    # Check if results are found and format the search results
    if not search_results:
        print(f"No results found for '{feature_to_search}'.")
    else:
        formatted_search_results = format_search_results(search_results)
        print(formatted_search_results)

For example when searching for 'fracmod', the following is displayed in the terminal

Code:
Search for: fracmod
~~~~~~~
HID: CASfracmod
Long Title: None
Short Title: fracmod
Syntax:
fracmod(Expr, Integer)

For a given expression and an integer n, returns the fraction a/b such that a/b=Expr mod n, where -√n/2<a≤√n/2 and 0≤b<√n/2

Example(s):
fracmod(41,121) ----> 2/3

See Also: CASchrem
~~~~~~~

One simple improvement that someone could suggest would be to remove the extra closing parentheses in

Code:
fracmod(Expr,Integer))

If more things get noticed, more things get fixed Smile

edit: I noticed that HP Museum didn't allow a .py file upload here. Shouldn't that be changed, since the Prime supports a version of micro python?

- neek
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Improving the Help text on HP Prime - ftneek - 07-03-2024 09:02 AM



User(s) browsing this thread: 3 Guest(s)