G3516_And_note_コマンド処理変更
2025年2月25日
9:05
G3516_andoroid_and_note_command_pro_change
毎日データの変換作業
C:\Users\goma0099\Desktop\com.companyname.And_note\files
必ず、アプリを終了させます
無事変換が出来ました
ボタン1、「実行/保存」を押したときの処理を変更します
★ 下記関数は、改良が終わった時点で、削除されます
現行処理の見直し/「行/保存」ボタンの処理を調査します
音声変換のテキストを入力したあと
(わかりにくくて申し訳ありません)
追加したい処理
配下フォルダ command でファイル検索します
Yes/Noの処理が必要となります
プロジェクトフォルダをバックアップします
ボタン1の修正
コマンドとキーワードの識別を考察します
以下は、現状調査のためのコード表示です
将来追加されるであろうコマンドの考察
現時点での決定事項
コードの修正を始める前に、データを修正します
コマンド.txt の修正
グローバル変数を追加します
public static string Command_yes_no_type = ""; // Yes/No確認タイプ
public static string[] Command_yes_no_data = new string[2+1]; // Yes/No 指図データ (2件まで)
「保存/実行」ボタンの処理が原型をとどめないほど修正されます
// 保存 実行
private void Button1_Click(object? sender, EventArgs e)
{
string edit_txt = Edt_tbl[0].Text.Trim();
string[] fld_tbl = new string[50];
if (edit_txt == "") return; // 入力がありません
// 分解します
fld_tbl = edit_txt.Split(' ', ' ');
switch (Main_name)
{
case "音声変換":
// 日付の場合
if (Audio_txt_date_chk(fld_tbl) == true) break;
// コマンドやキーワードの場合
if (Audio_txt_command_keyword_chk(fld_tbl) == true) break;
// 日付指定もコマンド指定もないので、通常の保存処理を実行します
edit_txt_sav(0, 0, 0, edit_txt);
Edt_tbl[0].Text = "";
break;
}
}
新しい関数が追加されます
// 先頭に日付が入力された場合の処理です
private bool Audio_txt_date_chk(string[] prm_fld_tbl)
{
string[] ans_tbl = new string[50];
string msg_cst = "";
DateTime dt = DateTime.Now;
int today = (dt.Year * 365) + (dt.Month * 31) + dt.Day;
int inp_day, yy_all, mm, dd;
bool dsp_flg = false;
// 音声入力の先頭が日付であるか検査します
if (Date_input_chk(prm_fld_tbl, ans_tbl) == false) return false;
msg_cst = ans_tbl[0] + "年" + ans_tbl[1] + "月" + ans_tbl[2] + "日" + ans_tbl[3];
yy_all = int.Parse(ans_tbl[0]);
mm = int.Parse(ans_tbl[1]);
dd = int.Parse(ans_tbl[2]);
inp_day = (yy_all * 365) + (mm * 31) + dd;
if (ans_tbl[3] != "")
{
// 日付の後方に文字列があり、予定登録と判定します
// 指示された日付が未来であることも判定します
if (today < inp_day)
{
// 後方のメッセージを指定された未来に更新します
edit_txt_sav(yy_all, mm, dd, ans_tbl[3]);
msg_cst += " 予定を保存しました";
dsp_info(msg_cst);
}
else dsp_flg = true;
}
else dsp_flg = true;
if (dsp_flg == true)
{
// 指示された日付のデータを表示します
Main_name_set("過去未来表示");
dsp_note(yy_all, mm, dd);
msg_cst += " を表示しました";
dsp_info(msg_cst);
}
return true;
}
date_input_chk() 関数が修正されます
// 先頭の日付入力を判定します
private bool Date_input_chk(string[] prm_fld_tbl, string[] prm_ans_tbl)
{
string[] cal_tbl = new string[30];
int tmp_dat;
int yy_all, mm, dd;
int dd_tbl_no;
DateTime dt = DateTime.Now;
string msg_cst = "";
int msg_fld_sta = 3;
int cnt;
if (prm_ans_tbl.Length < 4)
{
msg2("date_input_chk()", "配列個数が不足しています", "");
return false;
}
yy_all = mm = dd = 0;
cal_tbl = prm_fld_tbl[0].Split('年', '月', '日');
// 年度が省略されて月日だけの場合があります
if (cal_tbl.Length < 2)
{
// フリック入力にも対応します
// 区切り文字に、半角スペース、全角スペースを追加しました
// 予定入力の場合 2/20 歯科予約などのように入力しますが
// 「/」だけだと、日データが分割されず、データとして登録されます
cal_tbl = prm_fld_tbl[0].Split('/',' ',' ');
if(cal_tbl.Length < 2) return false;
}
// 先頭が数値変換出来る
if (int.TryParse(cal_tbl[0], out tmp_dat) == false) return false;
if (1980 <= tmp_dat && tmp_dat <= 2199)
{
yy_all = tmp_dat;
if (int.TryParse(cal_tbl[1],out mm) == false) return false;
dd_tbl_no = 2;
}
else
{
mm = tmp_dat;
// 年度の明示がない場合、本年度に限定する
yy_all = dt.Year;
dd_tbl_no = 1;
}
if (mm < 1 || 12 < mm) return false; // 月範囲エラー
if (int.TryParse(cal_tbl[dd_tbl_no],out dd) == false) return false;
if(dd < 1 || 31 < dd) return false; // 日付範囲エラー
// 将来後方に続く文字列も扱う場合を考慮します
msg_fld_sta = dd_tbl_no + 1;
if(msg_fld_sta < cal_tbl.Length)
{
for (cnt = msg_fld_sta; cnt < cal_tbl.Length; cnt++)
msg_cst += cal_tbl[cnt].Trim();
}
prm_ans_tbl[0] = yy_all.ToString("D4");
prm_ans_tbl[1] = mm.ToString("D2");
prm_ans_tbl[2] = dd.ToString("D2");
prm_ans_tbl[3] = msg_cst;
return true;
}
新しい関数が追加されます
// 先頭にコマンドやキーワードが入力された場合の処理です
private bool Audio_txt_command_keyword_chk(string[] prm_fld_tbl)
{
int fld_max = 0;
string add_cst = "";
bool key_flg = false;
bool command_flg = false;
string[] key_ans_tbl = new string[20];
string[] command_ans_tbl = new string[20];
if (prm_fld_tbl.Length == 0) return false;
// 削除はスペル表示とコマンド表示がありますが、後方パラメータの有無で識別出来ます
// すべてのパターンで、この法則は成立しますか?
// 削除 行指定
// 除外ワード ワード指定
//
// キーワード(英単語)を先に判定します
fld_max = Command_keyword_chk("キーワード", prm_fld_tbl, key_ans_tbl);
if (0 < fld_max)
{
add_cst = prm_fld_tbl[0] + "\r\n";
msg2("キーワード", key_ans_tbl[1], key_ans_tbl[2]);
for (int i = 0; i < fld_max; i++)
{
if (key_ans_tbl[i] == "") continue;
add_cst += key_ans_tbl[i] + "\r\n";
}
Edt_tbl[0].Text = add_cst;
key_flg = true;
}
fld_max = Command_keyword_chk("コマンド", prm_fld_tbl, command_ans_tbl);
if (0 < fld_max)
{
// 0:種別(コマンド) 1:同義語 2:指図データ 3:指図データ
Command_yes_no_type = "";
switch (command_ans_tbl[1])
{
case "除外ワード":
case "削除":
case "結果登録":
case "検索表示":
Command_yes_no_type = command_ans_tbl[1];
// 指図データ
Command_yes_no_data[0] = "";
Command_yes_no_data[1] = "";
if (command_ans_tbl[2] != "") Command_yes_no_data[0] = command_ans_tbl[2];
if (command_ans_tbl[3] != "") Command_yes_no_data[1] = command_ans_tbl[3];
break;
}
if (Command_yes_no_type != "")
{
dsp_info("「" + command_ans_tbl[1] + "」" + " を実行する場合、Yesボタンを押してください");
But_tbl[4].Text = "No";
But_tbl[5].Text = "Yes";
}
command_flg = true;
}
if (key_flg == false && command_flg == false) return false;
return true;
}
新しい関数が追加されます
// コマンド、キーワード判定
private int Command_keyword_chk(string prm_type, string[] prm_fld_tbl, string[] prm_ans_tbl)
{
string fil_path;
string[] rec_tbl = new string[50];
int fld_max;
int ans_fld_max = 0;
if (prm_type == "コマンド")
{
fil_path = Path_command + "/" + prm_fld_tbl[0] + ".txt";
if (File.Exists(fil_path) == false) return 0;
fld_max = com_txt_tbl_red(fil_path, 0, rec_tbl);
if (fld_max == 0) return 0;
// 種別 , 同義語
prm_ans_tbl[0] = rec_tbl[0]; // コマンド
prm_ans_tbl[1] = rec_tbl[1]; // 同義語 省略されないことが前提です
ans_fld_max = 2;
if (prm_fld_tbl[1] != "")
{
prm_ans_tbl[2] = prm_fld_tbl[1]; // 削除の行番号 or 結果名
ans_fld_max = 3;
}
if (prm_fld_tbl[2] != "")
{
prm_ans_tbl[3] = prm_fld_tbl[2]; // 結果名の行番号
ans_fld_max = 4;
}
}
else
{
// 現在2タイプしかないので、指示がなければキーワードとします
fil_path = Path_key + "/" + prm_fld_tbl[0] + ".txt";
if (File.Exists(fil_path) == false) return 0;
fld_max = com_txt_tbl_red(fil_path, 0, rec_tbl);
if (fld_max == 0) return 0;
if (prm_ans_tbl.Length < fld_max) fld_max = prm_ans_tbl.Length; // オーバーフロー補正
// スペルと後方に続くも解説文書を返答します
for (int i = 0; i < fld_max; i++)
{
prm_ans_tbl[i] = rec_tbl[i];
ans_fld_max = i + 1;
}
}
return ans_fld_max;
}
プログラムモード代入処理を変更します
臨時インフォメーションの初期化を修正します
英単語の動作を確認します
「結果登録」コマンドの動作を確認します
「結果登録」コマンドの動作を確認します
ここから先は、コードが作られていません
長くなったので、コマンドによるデータ処理は次回に持ち越しします