未分類

Golangで、以下のXML分の中から、<tag k="route" v="bus"/>を発見した時に、refの要素を参照にして位置情報を取り出すプログラムを書いて

<osm>
  <node id="2197214759" lat="35.5714149" lon="139.5880043" version="1" timestamp="2013-03-12T09:31:19Z" changeset="15336763" uid="1258339" user="k___0e0">
    <tag k="highway" v="bus_stop"/>
    <tag k="name" v="有馬第二団地前"/>
  </node>
  <node id="2197214762" lat="35.5715628" lon="139.5875429" version="1" timestamp="2013-03-12T09:31:19Z" changeset="15336763" uid="1258339" user="k___0e0">
    <tag k="highway" v="bus_stop"/>
    <tag k="name" v="有馬第二団地前"/>
  </node>
  <relation id="2814953" version="38" timestamp="2023-06-14T08:20:58Z" changeset="137316398" uid="1687166" user="U20">
   <member type="node" ref="2197214759" role="backward_stop"/>
    <member type="node" ref="2197214762" role="forward_stop"/>
    <tag k="route" v="bus"/>
  </relation>
</osm>

ChatGPTの回答

指定されたXMLデータから を検出し、それに対応する ref 要素を参照にして位置情報を取得するGolangのプログラムを以下に示します。このプログラムは、encoding/xml パッケージを使用してXMLを解析します。

package main

import (
	"encoding/xml"
	"fmt"
	"log"
	"strings"
)

type OSM struct {
	XMLName xml.Name `xml:"osm"`
	Nodes   []Node   `xml:"node"`
	Relations []Relation `xml:"relation"`
}

type Node struct {
	ID       int64   `xml:"id,attr"`
	Lat      float64 `xml:"lat,attr"`
	Lon      float64 `xml:"lon,attr"`
	Tags     []Tag   `xml:"tag"`
}

type Relation struct {
	ID       int64   `xml:"id,attr"`
	Members  []Member `xml:"member"`
	Tags     []Tag    `xml:"tag"`
}

type Member struct {
	Type string `xml:"type,attr"`
	Ref  string `xml:"ref,attr"`
	Role string `xml:"role,attr"`
}

type Tag struct {
	K string `xml:"k,attr"`
	V string `xml:"v,attr"`
}

func main() {
	xmlData := `
	<osm>
		<node id="2197214759" lat="35.5714149" lon="139.5880043" version="1" timestamp="2013-03-12T09:31:19Z" changeset="15336763" uid="1258339" user="k___0e0">
			<tag k="highway" v="bus_stop"/>
			<tag k="name" v="有馬第二団地前"/>
		</node>
		<node id="2197214762" lat="35.5715628" lon="139.5875429" version="1" timestamp="2013-03-12T09:31:19Z" changeset="15336763" uid="1258339" user="k___0e0">
			<tag k="highway" v="bus_stop"/>
			<tag k="name" v="有馬第二団地前"/>
		</node>
		<relation id="2814953" version="38" timestamp="2023-06-14T08:20:58Z" changeset="137316398" uid="1687166" user="U20">
			<member type="node" ref="2197214759" role="backward_stop"/>
			<member type="node" ref="2197214762" role="forward_stop"/>
			<tag k="route" v="bus"/>
		</relation>
	</osm>
	`

	var osmData OSM
	err := xml.Unmarshal([]byte(xmlData), &osmData)
	if err != nil {
		log.Fatal(err)
	}

	for _, relation := range osmData.Relations {
		for _, tag := range relation.Tags {
			if tag.K == "route" && tag.V == "bus" {
				for _, member := range relation.Members {
					if member.Type == "node" {
						node := getNodeByID(member.Ref, osmData.Nodes)
						if node != nil {
							fmt.Printf("Bus Stop: %s\n", getNodeName(node))
							fmt.Printf("Coordinates: Lat %f, Lon %f\n\n", node.Lat, node.Lon)
						}
					}
				}
			}
		}
	}
}

func getNodeByID(ref string, nodes []Node) *Node {
	for _, node := range nodes {
		if fmt.Sprintf("%d", node.ID) == ref {
			return &node
		}
	}
	return nil
}

func getNodeName(node *Node) string {
	for _, tag := range node.Tags {
		if tag.K == "name" {
			return tag.V
		}
	}
	return ""
}

このプログラムは、与えられたXMLデータから を見つけ、それに関連する ref 要素を参照してバス停の位置情報を取得して表示します。XMLデータは xmlData 変数に直接格納されていますが、実際のプログラムではファイルから読み込むこともできます。コード内のコメントに従って、XMLデータ構造やタグを調整してください。


世界が変わる

生成AIを使わない奴は、"死ぬ" ―― 文字通りの意味で。

2023,江端さんの忘備録

15年くらい前に『地球温暖化はウソだ』と、自信満々に言っていた同僚がいました(何年か前に転職しましたが)。

I had a colleague about 15 years ago who confidently said, 'Global warming is a lie' (he changed jobs some years ago).

私は、こんなコラムを書いていたくらいですので、同意はしませんが、別段反論もしませんでした。

I even wrote such a column, so I disagreed but did not argue otherwise.

だって、未来は誰にも分からないのだから。

Because no one knows what the future holds.

-----

ただ、車から出て玄関に到着するまでの、数十秒の間でも、体が燃えるような体験をしている、この夏においても、

But even in the dozens of seconds it takes to get out of the car and arrive at the front door, my body is likely to be burning experience, even this summer,

―― 今も彼は、『地球温暖化はウソだ』と言いつづけているのだろうか?

"Does he still say 'global warming is a lie'?"

と、ふと思い出します。

I am suddenly reminded of him.

彼なら、『これは異常気象であり、地球温暖化とは関係がない』と言っているかもしれんなぁ、とも思ったりしています。

I wonder if he might say, "This is abnormal weather and has nothing to do with global warming.

―― 数理モデル + シミュレーション でのノーベル"物理学"賞が来たーーーー!!

2023,江端さんの忘備録

すっげー忙しくて、苦しくて、時間がないのですが、今度の学会用プレゼン資料用に、こんな絵を作っていました ―― フリー素材をかき集めて、2時間もかけて。

I've been busy, struggling, and I don't have much time, but I was making this picture for a presentation material for an upcoming conference -- two hours of scouring free materials.

典型的な『現実逃避』です。

It is a typical 'escape from reality.'

-----

あああああ、色々と面倒で、嫌だーーー。

Aaahhhh, all kinds of trouble, I hate it!

この夏季休暇、毎日12時間以上もPC睨みつけて作業していたのに、思うようにプログラムが動かん。

I've been staring at my computer for over 12 hours daily this summer vacation, but the program doesn't work as I want.

・・・明日が、来なければいいのに。

I wish tomorrow would never come.

と、8月31日の多くの子どもと同じ気持ちになっています。

I feel the same way as many children on August 31.

「自殺対策白書(内閣府発行)」を、ベッドの脇において、寝る前にページを捲っている

 

 

 

2016,江端さんの忘備録

本日は、コラムがリリースされた日なので、日記はお休みです。

My new column is released today, so I am taking a day off.

Let's turn the world by "Number" Accident resulting in injury or death (34)."

Data tell us a chilly reality of one-under of trains.

-----

「自殺対策白書(内閣府発行)」を、ベッドの脇において、寝る前にページを捲っている

Keeping a white book of measure against suicide ( pressed by Cabinet Office) at the bed and reading the book before sleep,

そういう主任研究員は、

Such a senior researcher

実在します。

Has existed.

2023,江端さんの忘備録

―― 快適な閉空間での食事をする為の、積極的なトイレでの食事の利用

この話を長女としていたのですが、娘は1回だけトライアルしたことがあるそうです。

I discussed this with my oldest daughter, who has only done one trial.

この話を聞いて、

Listen to this story,

―― 娘に負けた

"My daughter beat me."

と、ガックリしました。

I was gutted.

-----

娘は、フィールドワークにもとづき、以下の課題を明らかにしました。

Based on the fieldwork, my daughter identified the following issues.

(1)コンビニ弁当などは、音が出やすくて、周囲にバレるリスクが高い。"音"の出難い軽食(菓子パン等など)に限定される

(1) Convenience store lunches, for example, tend to make a lot of noise, and there is a high risk of being recognized by others." Therefore, light meals (e.g., sweet bread) are limited to those that do not make a "noise."

(2)人の出入りが気になって、あまり気が休まらない

Cause of people coming and going, I don't feel very comfortable.

私は『衛生面についての抵抗感』について尋ねたのですが、それについては、「あまり気にならなかった」とのことです。

I asked about 'resistance to hygiene,' she said she wasn't too concerned.

まあ、この辺りの定量比較については、今後の研究発表が待たれるところです。

Well, I am waiting for the publication of future studies on quantitative comparisons in this area.

-----

シャレで、「便所飯」をキーワードとして、論文・文献サーチをしてみたのですが、

As a joke, I did an article and literature search using "lunch in the toilet" in Japanese as a keyword,

―― ヒット数、59件

"Number of hits, 59."

です。

「便所飯」を英語でなんというのか、よく分かりませんでしたので、以下の検索キーで探してみました。

I wasn't sure how to say these Japanese words in English, so I searched for them using the following search key.

"food in the toilet" | "food in toilet" | "lunch in the toilet" | "lunch in toilet"

―― ヒット数、60件

"Number of hits, 60"

うん、大丈夫です。

Yeah, it's okay.

「便所飯」はインターナショナルで、かつ、グローバル展開されつつあります。

"Food in the toilet" is international and becoming increasingly global.

2023,江端さんの技術メモ

GolangでOSMファイルから、<tag k="highway" v="bus_stop"/>が入っているnode情報と、その中にあるtag k="name"の情報を出して

と、ChatGPTに頼んだら、サクッと作ってくれました。

package main

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

type Osm struct {
	XMLName xml.Name `xml:"osm"`
	Nodes   []Node   `xml:"node"`
}

type Node struct {
	XMLName xml.Name `xml:"node"`
	Lat     string   `xml:"lat,attr"`
	Lon     string   `xml:"lon,attr"`
	Tags    []Tag    `xml:"tag"`
}

type Tag struct {
	XMLName xml.Name `xml:"tag"`
	Key     string   `xml:"k,attr"`
	Value   string   `xml:"v,attr"`
}

func main() {
	// XMLファイルの読み込み
	xmlFile, err := os.Open("tsuzuki.osm")
	if err != nil {
		log.Fatal(err)
	}
	defer xmlFile.Close()

	// XMLデータの読み込み
	xmlData, err := ioutil.ReadAll(xmlFile)
	if err != nil {
		log.Fatal(err)
	}

	var osm Osm

	// XMLデータのUnmarshal
	err = xml.Unmarshal(xmlData, &osm)
	if err != nil {
		log.Fatal(err)
	}

	// <tag k="highway" v="bus_stop"/> のノード情報を表示
	for _, node := range osm.Nodes {
		hasBusStopTag := false
		var busStopName string

		// ノード内のタグ情報を探索
		for _, tag := range node.Tags {
			if tag.Key == "highway" && tag.Value == "bus_stop" {
				hasBusStopTag = true
			}
			if tag.Key == "name" {
				busStopName = tag.Value
			}
		}

		if hasBusStopTag {
			fmt.Printf("Bus Stop Name: %s, Lat: %s, Lon: %s\n", busStopName, node.Lat, node.Lon)
			//fmt.Printf("%s, %s,%s\n", busStopName, node.Lat, node.Lon)
		}
	}
}

>go run bus_stop2.go
Bus Stop Name: 川和町, Lat: 35.5341695, Lon: 139.5461286
Bus Stop Name: 川和町, Lat: 35.5344793, Lon: 139.5458792
Bus Stop Name: 東名江田, Lat: 35.5628753, Lon: 139.5577658
Bus Stop Name: 石橋, Lat: 35.5209186, Lon: 139.5571699
Bus Stop Name: 桜通り, Lat: 35.5677990, Lon: 139.5446995
Bus Stop Name: 鶴蒔橋, Lat: 35.5496160, Lon: 139.5451910
Bus Stop Name: 鶴蒔橋, Lat: 35.5491291, Lon: 139.5461293
Bus Stop Name: 泉公園, Lat: 35.5480514, Lon: 139.5475269
Bus Stop Name: 市ヶ尾中学校前, Lat: 35.5468751, Lon: 139.5464900
Bus Stop Name: 市ヶ尾中学校前, Lat: 35.5468380, Lon: 139.5466080

2023,江端さんの技術メモ

https://josm.openstreetmap.de/wiki/Help/Action/JumpToPosition

ショートカットキー: Ctrl+J

または、ここをクリックすると、

このダイアログが出てくので、ここに名称または座標を入れる。

2023,江端さんの忘備録

私の娘たちも、他の子ども達と同様に、様々なトラブルに巻き込まれているようです。

Like many other children, my daughters get into all kinds of trouble.

(例えば、このページの話とか)

(For example, the story on this page.)

ところが、私のところには、滅多にトラブルの話が届きません。

However, I seldom receive stories of trouble.

-----

江端家には、独自のトラブルシューティングのワークフローシステムがあるようです。

The Ebata family seems to have its troubleshooting workflow system.

(Step 1) 娘(たち) → 嫁さんへのインシデントの相談

(Step 1) Daughter(s) → Wife to discuss the incident

(Step 2) 娘(たち)嫁さんによる、その問題に対する重大度の評価

(Step 2) Assessment of the severity of the problem by the daughter(s) and wife

と、大体ここまでで、案件は片が付くようなのですが、非常に稀に、

And so far, the case seems to be generally cleared up, but very rarely,

(Step 3)父親(私)への、問題解決への依頼

(Step 3) Request the father (me) to solve the problem

が発生する、とのことのようです。

occurs, it seems to be the case.

これが、「届かない」理由です。

This is the reason why it is "unreachable."

-----

江端:「なんで? 私の問題への対応と解決は、確実で早いよ」

Ebata: "Why not? My response and solution to their problem is sure and fast."

嫁さん:「うん。これまで『相談してから大体2時間以内に、初弾が発射される』のを見てきた」

Wife: "Yes. So far, I've seen 'the first missile fired, usually within two hours of consulting.'"

江端:「じゃあ・・・」

Ebata: "Well..."

嫁さん:「パパ(私)の解決方法は、"歩兵戦"を行っているところに、"戦術核"を打ち込むような方法だからだよ」

Wife: "Because your solution is to launch a tactical nuke into an infantry battle."

-----

うん、確かにそうかもしれない。

Yeah, that may be true.

私の解決方法は、味方も含めて『紛争地帯全部を吹き飛ばす』という方法が多いです。

My solution is often to 'blow up the entire conflict zone,' including allies.

例えば、

For example,

- 部活が問題なら、その部を廃部に追い込む。

- If club activities are the problem, the club will be discontinued.

- 学校が問題なら、校長を退任させるか、可能なら学校を廃校に追い込む

- If the school is the problem, get the principal out of office or, if possible, close the school.

- 当事者間の事前協議をすっとばして、いきなり法的手続を開始する

- Skipping the prior consultation between the parties and starting legal proceedings out of the blue

つまり、『問題の発生原因を、根こそぎ消滅させる』です。

In other words, "to eliminate the cause of the problem at its root.

-----

ですので、嫁さんが私に「依頼」をする場合、その「落とし所」も付けてきます。

So, when my wife makes a "request" to me, she will also attach a "compromise" to it.

例えば『2、3人ほど犠牲にしてもかまわないけど、廃部にまで追い込まなくてもいい』などです。

For example, 'I don't mind sacrificing a couple of people, but it doesn't have to drive us to abolition.

嫁さん(文官)が戦略を指示し、私(武官)が戦術を立案、実行します。

My wife (civilian officer) directs the strategy, and I (military officer) plan and execute the tactics.

これが「江端家シビリアンコントロール」です。

This is the "Ebata Family Civilian Control."

―― 教師と紛争を起して、トラブルを法廷に持ち込んでみませんか

―― あなたは、その宿題と、うまくうけば、その教師も、ほぼ確実に「潰す」ことができます。

2017,江端さんの忘備録

(昨日の続きです)

(Continuation from yesterday)

では、作戦を伝授します。

Then, I will teach the strategy.

■まず、その宿題が客観的に、夏休み中に実施不可能であることを、数値で出してください。具体的には実施時間を、一日あたりの時間で算出できれば十分です。

- First of all, please let us know that homework is objectively impossible during the summer holidays. Specifically, it is sufficient to calculate the execution time in hours per day.

■そのような同意者を、最低でも10人、可能であれば100人オーダで、同意書を作成して下さい。

- Please make a consent form for such agreement, with a minimum of 10 people, possibly 100 persons order.

■保護者の同意があれば、それに越したことはありませんが、その同意書を、その教師ではなく「校長」と「市または県の教育委員会」に直接提出して下さい。新聞社などにも、一方的に送りつけても良いでしょう。

- If there is parental consent, it will be better. However that is not important. You should not send the consent paper to not the teacher. but "principal" and "city or provincial board of education", directly,

ここまでやれば、

If you do so far,

―― あなたは、その宿題と、うまくうけば、その教師も、ほぼ確実に「潰す」ことができます。

"You can almost "crush" the homework and, the teacher at the same time hopefully"

-----

大切なのは、「教師との直接対決」とか「保護者への協力」に持ち込まないことです。

The important thing is not to bring in "direct confrontation with teacher" or "cooperation with parents".

この作戦の目的は、「校長」「教育委員会」「マスコミ」を利用して、事態を炎上させることにあります。

The purpose of this strategy is to use the "principal", "board of education" and "mass communication" to make things flame up.

大丈夫です。

No problem.

炎上の火を燃やし始めるのは、あなたたちティーンエイジャですが、火を消すのは「大人」の仕事ですから。

What you "teenagers" should to is start burning fire. On the other hand, turning off the fire is a job of "adult".

もちろん、未成年である皆さんには、刑事罰は勿論、民事上の損害賠償請求などの法律上の責任は課せられません。

Of course, you are not subject to legal responsibilities such as claims for civil damages, as well as criminal punishment.

-----

さあ、残り少ない日々ですが、やるなら今です。

Now, it's a few days left, but now it's time to do it now

まだギリギリ間に合います。

It is still in time for it.

「宿題を完了させる労力」と、「炎上をしかける労力」を冷静に天秤にかけて、勝負をしかけましょう。

Let's calmly balance the "effort to complete homework" and "effort to deflate the fire" and start the game.

2017,江端さんの忘備録

お盆を過ぎるころから、心に黒いシミなっていた、夏休みの宿題。

From the end of the Bon event, I am afraid a black stain called "homework for summer vacation" becomes spread out your mind.

そして、今、ようやく宿題の全体の量を見て、青くなっているティンーンエイジャの皆さん。

Dear you, of the teenager who looks pale with looking at the whole amount of homework.

その宿題が、夏休み中に実施不可能であったことを立証して、

Why do not you prove that you cannot complete homework during a summer vacation, and

―― 教師と紛争を起して、トラブルを法廷に持ち込んでみませんか

"would you try to conflict with your teacher and cause a lawsuit

-----

実際のところ、無茶苦茶な量の宿題を出してくる、定量的計算のできない、教師は結構な数います。

Quite a few low-teachers can not quantitatively calculate a casual amount of homework.

実際、私は、

In fact,

■1日6時間、30日かけないとできないような、膨大な量の漢字の書取りをやらせた、中学時代の「ミヤモト」という創意工夫の能力のない教師と、

- A teacher named "Miyamoto" of junior high school teacher without creative ingenuity, who had writing of an enormous amount of kanji, which can not be done unless it took six hours a day, 30 days a day,

■自分ですらできないような、英語の原書の翻訳をやらせた、高校時代の「シズカ」という、世界史以外のことは何も知らない教師

- teachers named "Shizuka," who do not know anything other than the world history of high school, made us translate the original book of words,

を、今でも、「憎悪」の想いで記憶しています。

I still "hate" them even now.

ティーンエイジャの頃、生真面目だった私は、この宿題を真面目に取り組んで、夏休みに、夏休みらしいことを何もできませんでした。

When I was a serious teenager and working on this homework seriously, I could not do anything to play during summer vacation.

(続く)

(To be continued)