how to query OSM data in Java?

開放街圖OSM的公共圖資可以透過overpass-turbo介面查詢獲得。
若想利用Java程式碼查詢,可參考以下查詢範例。
其中,查詢指令可參考overpass-turbo範例指令,測試成功再代入程式。


/*
  QueryOSM.java
        展示如何用retrofit套件,同步及非同步(適用於Android),存取如下OSM圖資服務
                http://overpass-api.de/api/interpreter?data=xxx

        // 建立服務連線客戶端及請求內容
        OverpassService requestClient = OverpassServiceProvider.get();
        String request = composeRequest();
        
        // 非同步查詢圖資,適用於手機平板Android平台
        asyncRequest(requestClient, request);
        
        // 同步查詢圖資,適用於桌機Application應用
        OverpassQueryResult result = syncRequest(requestClient, request);
        postProcess(result);
 
執行步驟:
  javac QueryOSM.java
  java QueryOSM
run:
[out:json][timeout:25];
(
node[tourism](25.1735, 121.446, 25.1775, 121.455);
relation[!highway][type!='route'][!boundary](25.1735, 121.446, 25.1775, 121.455);
);
out center;
end of asyncRequest()
21 elements...
1. id:4326372453, type:node, lat:25.1761808, lon:121.4490491, name:五虎碑, wheelchair:limited
2. id:4384988658, type:node, lat:25.1750071, lon:121.4522078, name:文錙藝術中心, wheelchair:yes
3. id:4492221396, type:node, lat:25.1736267, lon:121.4473809, name:三化牆
4. id:4492221397, type:node, lat:25.1744069, lon:121.4474037, name:地球村雕像, wheelchair:limited
5. id:4492221399, type:node, lat:25.1735175, lon:121.4484658, name:淡江大學花牆
6. id:4492221425, type:node, lat:25.1749949, lon:121.450678, name:閱讀的少女, wheelchair:yes
7. id:4502075211, type:node, lat:25.1751384, lon:121.4523232, name:旅者
8. id:4502075212, type:node, lat:25.1739938, lon:121.4505047, name:李雙澤紀念碑, wheelchair:yes
9. id:4502075213, type:node, lat:25.1761919, lon:121.4499374, name:福園金鷹銅雕, wheelchair:no
10. id:4502075222, type:node, lat:25.1738907, lon:121.4475716, name:驚聲銅像, wheelchair:limited
11. id:4507662408, type:node, lat:25.1741082, lon:121.4474671, name:溫馨, wheelchair:yes
12. id:5012978611, type:node, lat:25.1741784, lon:121.4507282, name:黃河母親, wheelchair:no
13. id:5072580167, type:node, lat:25.1769149, lon:121.4495309
14. id:5130535622, type:node, lat:25.1757202, lon:121.4496844, name:會文館, wheelchair:yes
15. id:5132288341, type:node, lat:25.1741586, lon:121.4508061
16. id:5132288342, type:node, lat:25.174208, lon:121.4475417
17. id:6050843218, type:node, lat:25.1770813, lon:121.449821
18. id:8991981256, type:node, lat:25.1750049, lon:121.4480033, name:淡江願景牆, wheelchair:yes
19. id:3974590, type:relation, lat:0.0, lon:0.0, type:multipolygon, name:操場
20. id:3983402, type:relation, lat:0.0, lon:0.0, type:multipolygon, name:松濤廣場
21. id:7530081, type:relation, lat:0.0, lon:0.0, type:multipolygon

Response{protocol=http/1.1, code=200, message=OK, url=http://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A25%5D%3B%0A%28%0Anode%5Btourism%5D%2825.1735%2C%20121.446%2C%2025.1775%2C%20121.455%29%3B%0Arelation%5B%21highway%5D%5Btype%21%3D%27route%27%5D%5B%21boundary%5D%2825.1735%2C%20121.446%2C%2025.1775%2C%20121.455%29%3B%0A%29%3B%0Aout%20center%3B}
end of syncRequest()
21 elements...
1. id:4326372453, type:node, lat:25.1761808, lon:121.4490491, name:五虎碑, wheelchair:limited
2. id:4384988658, type:node, lat:25.1750071, lon:121.4522078, name:文錙藝術中心, wheelchair:yes
3. id:4492221396, type:node, lat:25.1736267, lon:121.4473809, name:三化牆
4. id:4492221397, type:node, lat:25.1744069, lon:121.4474037, name:地球村雕像, wheelchair:limited
5. id:4492221399, type:node, lat:25.1735175, lon:121.4484658, name:淡江大學花牆
6. id:4492221425, type:node, lat:25.1749949, lon:121.450678, name:閱讀的少女, wheelchair:yes
7. id:4502075211, type:node, lat:25.1751384, lon:121.4523232, name:旅者
8. id:4502075212, type:node, lat:25.1739938, lon:121.4505047, name:李雙澤紀念碑, wheelchair:yes
9. id:4502075213, type:node, lat:25.1761919, lon:121.4499374, name:福園金鷹銅雕, wheelchair:no
10. id:4502075222, type:node, lat:25.1738907, lon:121.4475716, name:驚聲銅像, wheelchair:limited
11. id:4507662408, type:node, lat:25.1741082, lon:121.4474671, name:溫馨, wheelchair:yes
12. id:5012978611, type:node, lat:25.1741784, lon:121.4507282, name:黃河母親, wheelchair:no
13. id:5072580167, type:node, lat:25.1769149, lon:121.4495309
14. id:5130535622, type:node, lat:25.1757202, lon:121.4496844, name:會文館, wheelchair:yes
15. id:5132288341, type:node, lat:25.1741586, lon:121.4508061
16. id:5132288342, type:node, lat:25.174208, lon:121.4475417
17. id:6050843218, type:node, lat:25.1770813, lon:121.449821
18. id:8991981256, type:node, lat:25.1750049, lon:121.4480033, name:淡江願景牆, wheelchair:yes
19. id:3974590, type:relation, lat:0.0, lon:0.0, type:multipolygon, name:操場
20. id:3983402, type:relation, lat:0.0, lon:0.0, type:multipolygon, name:松濤廣場
21. id:7530081, type:relation, lat:0.0, lon:0.0, type:multipolygon

end of main()
BUILD SUCCESSFUL (total time: 1 minute 2 seconds)

  參考:
  a. Retrofit 2 – Synchronous and asynchronous call example
        https://howtodoinjava.com/retrofit2/retrofit-sync-async-calls/
  b. https://github.com/zsoltk/overpasser
        hu.supercluster.overpasser.adapter
            OverpassQueryResult
            OverpassQueryResult.Element
            OverpassQueryResult.Element.Tags
            OverpassService
  c. 引用函數庫
      compile/run: 
        okhttp-3.14.9.jar
        okio-1.17.2.jar
        converter-gson-2.10.2.jar
        gson-2.8.5.jar
        retrofit-2.10.2.jar
      compile/run tests:
        byte-buddy-1.11.3.jar
        byte-buddy-agent-1.11.3.jar
        mockito-core-3.11.2.jar
        objenesis-3.2.jar
 */
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import hu.supercluster.overpasser.library.output.OutputFormat;
import hu.supercluster.overpasser.library.output.OutputModificator;
import hu.supercluster.overpasser.library.output.OutputOrder;
import hu.supercluster.overpasser.library.output.OutputVerbosity;
import hu.supercluster.overpasser.library.query.OverpassQuery;
 
import hu.supercluster.overpasser.adapter.OverpassQueryResult;
import hu.supercluster.overpasser.adapter.OverpassQueryResult.Element;
import hu.supercluster.overpasser.adapter.OverpassQueryResult.Element.Tags;
import hu.supercluster.overpasser.adapter.OverpassService;
import hu.supercluster.overpasser.adapter.OverpassServiceProvider;

import java.lang.reflect.Field;
import java.util.List;
/**
 *
 * @author seke
 */

public class QueryOSM {
    
    // 可利用下址測試查詢指令
    //     http://overpass-turbo.eu/
    public static String composeRequest()
    {
/* 查詢範例1: 
        在(47.48047027491862,19.039797484874725,47.51331674014172,19.07404761761427)範圍內
        列出所有非私人停車場
        
    A. 查詢指令
    ["out":"json"]["timeout":"30"];
    (
        node
            ["amenity"="parking"]
            ["access"!="private"]
            (47.48047027491862,19.039797484874725,47.51331674014172,19.07404761761427);
            <;
    );
    out body center qt 100;

    B. 組合查詢指令方法
      String query = new OverpassQuery()
        .format(OutputFormat.JSON)
        .timeout(30)
        .filterQuery()
            .node()
            .amenity("parking")
            .tagNot("access", "private")
            .boundingBox(
                47.48047027491862, 19.039797484874725,
                47.51331674014172, 19.07404761761427
            )
        .end()
        .output(OutputVerbosity.BODY, OutputModificator.CENTER, OutputOrder.QT, 100)
        .build()
        ;
*/

/* 查詢範例2: 
        在(25.1735, 121.446, 25.1775, 121.455)範圍內,撈取
           非座椅設施,商店,觀光點,辦公室,繄急設施之節點
           屬於大學設施之線條,關係
           不屬於公路、路線、森林、邊界之線條,關係
        列出其中心位置及相關屬性(標籤)

        A. 查詢指令
    [out:json][timeout:25];
    // gather results
    (
      node[amenity][amenity!=bench](25.1735, 121.446, 25.1775, 121.455);
      node[shop](25.1735, 121.446, 25.1775, 121.455);
      node[tourism](25.1735, 121.446, 25.1775, 121.455);
      node[office](25.1735, 121.446, 25.1775, 121.455);
      node[emergency](25.1735, 121.446, 25.1775, 121.455);
      //way[amenity="university"](25.1735, 121.446, 25.1775, 121.455);
      relation[amenity="university"](25.1735, 121.446, 25.1775, 121.455);
      way[!highway][type!="route"][landuse!="forest"][!boundary](25.1735, 121.446, 25.1775, 121.455);
      relation[!highway][type!="route"][!boundary](25.1735, 121.446, 25.1775, 121.455);
    );
    // print results
    out center;
---
  註:  淡江大學之範圍為 25.1735, 121.446, 25.1775, 121.455
*/       
       String query = String.join("\n",
               "[out:json][timeout:25];",
               "(",
//               "node[amenity][amenity!=bench](25.1735, 121.446, 25.1775, 121.455);",
//               "node[shop](25.1735, 121.446, 25.1775, 121.455);",
               "node[tourism](25.1735, 121.446, 25.1775, 121.455);",
//               "node[office](25.1735, 121.446, 25.1775, 121.455);",
//               "node[emergency](25.1735, 121.446, 25.1775, 121.455);",
//               "relation[amenity='university'](25.1735, 121.446, 25.1775, 121.455);",
//               "way[!highway][type!='route'][landuse!='forest'][!boundary](25.1735, 121.446, 25.1775, 121.455);",
               "relation[!highway][type!='route'][!boundary](25.1735, 121.446, 25.1775, 121.455);",
               ");",
               "out center;");

        System.out.println(query);
        return query;
    }
    
    public static void asyncRequest(OverpassService apiClient, String request)
    {
       //Call call = service.interpreter(query);
       apiClient.interpreter(request).enqueue(new Callback()
       {
        @Override
        public void onResponse(Call call, Response response)
        {
            if(response.isSuccessful()==false)
            {
                System.out.println("asyncRequest: response.isSuccessful(): false");
                System.out.println(response.errorBody());
                return;
            }
            
            OverpassQueryResult result = response.body();
            postProcess(result);
         }

        public void onFailure(Call call, Throwable t) {
        // DO failure handling 
          System.out.println("onFailure");
          System.out.println(t.getLocalizedMessage());
        }
       });
       
       System.out.println("end of asyncRequest()");
    }
    
    public static OverpassQueryResult syncRequest(OverpassService apiClient, String request)
    {
        OverpassQueryResult result = null;
        Call callSync =   apiClient.interpreter(request); 

        try
        {
            Response response = callSync.execute();
            //OverpassQueryResult apiResponse = response.body();
     
            //API response
            System.out.println(response);
            result = response.body();
        }
        catch (Exception ex) 
        { 
            ex.printStackTrace();
        }
        
        System.out.println("end of syncRequest()");
        return result;
    }
    
    public static void postProcess(OverpassQueryResult result)
    {
        if(result==null) return;

        // DO success handling 
        StringBuilder sb = new StringBuilder();
        System.out.println(result.elements.size() + " elements...");
        int count = 1;
        for (Element p : result.elements) 
        {
            sb.append(count); count++;
            sb.append(String.format(". id:%s, type:%s, lat:%s, lon:%s", p.id, p.type, p.lat, p.lon));
            Tags tags = p.tags;
            for (Field f : tags.getClass().getFields()) {
                f.setAccessible(true);
                try 
                {
                    if (f.get(tags) != null) {
                       sb.append(String.format(", %s:%s", f.getName(), f.get(tags)));
                    }
                }
                catch (IllegalAccessException e)
                { // shouldn't happen because I used setAccessible
                }

            }
            //if(p.tags. != null)
            //  sb.append(String.format("tags:%s", p.tags.name));
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
    
    public static void main(String args[])
    {
        // 建立服務連線客戶端及請求內容
        OverpassService requestClient = OverpassServiceProvider.get();
        String request = composeRequest();
        
        // 非同步請求
        asyncRequest(requestClient, request);
        
        // 同步請求
        OverpassQueryResult result = syncRequest(requestClient, request);
        postProcess(result);
        
        System.out.println("end of main()");
    }
}

tips on installation of xrdp for remote desktop connection to linux machines

大家都知道,Linux桌面跑的是X Windows視窗系統。微軟Windows如果想要連上Linux桌面,一種作法是本身主機消耗硬碟,裝上X Windows伺服軟體MobaXterm或VcXsrv,甚至加上微軟應用商店的免費Linux作業系統,例如Ubuntu,此作法步驟可詳Lainme's Blog。另一種作法是遠方Linux主機安裝tightvnc server及xrdp套件,微軟Windows只要沿用原來的遠端桌面連線(mstsc.exe),即可使用rdp協定,連上Linux桌面。後者作法,剪貼簿可用,聲音則待個別測試。以下將依據Linux作業系統為 Ubuntu 或 CentOS,分別介紹其安裝訣竅。

A. Ubuntu 安裝 xrdp 作法

-- 先去除舊套件干擾 sudo apt-get remove xrdp tightvncserver # 只刪執行檔 sudo apt-get purge xrdp tightvncserver # 刪除執行檔及相關組態檔 sudo dpkg --purge xrdp tightvncserver # 刪除執行檔及相關組態檔 sudo dpkg -S /etc/xrdp/startwm.sh # 查檔案所屬套件 -- 安裝tightvncserver及xrdp套件 sudo apt-get install tightvncserver # 一定要先安裝此視窗套件 sudo apt-get install xrdp # 然後安裝此傳輸套件,才會順利偵測運用視窗套件 sudo vi /etc/xrdp/startwm.sh # 加入管理視窗指令 xfce4-session # 若未安裝,可使用apt-get install xfce4-session -- 啟動服務 sudo service xrdp status # 詢問xrdp服務狀態 sudo service xrdp start # 啟動xrdp服務 註: 若連線過程,顯示詢息,缺rsakeys.ini金鑰,可如下產生金鑰 cd /etc/xrdp sudo xrdp-keygen xrdp # generate /etc/xrdp/rsakeys.ini -- 測試連線 sudo netstat -tulpn # 觀看是否3389及3350連接埠有監聽服務 -- rdp連線過程,適用於 Ubuntu 16.04.6 LTS (1) xrdp (3389) # 選擇 sesman-Xvnc 模式 (2) xrdp-sesman (3350,root) (3) xrdp-chansrv # 執行 /etc/xrdp/startwm.sh 及 xfce4-session (4) Xvnc (59xx) -- rdp連線過程,適用於 Ubuntu 18.04.5 LTS (1) xrdp (3389) # 選擇 Xorg 模式 (2) xrdp-sesman (3350,root) (3) xrdp-chansrv # 執行 /etc/xrdp/startwm.sh 及 xfce4-session (4) Xorg 註: xrdp安裝apt-get內建版本即可,不須安裝 https://github.com/neutrinolabs/xrdp.git

B. CentOS 安裝 xrdp 作法

-- 安裝tightvnc-server及xrdp套件 sudo yum erase xrdp tightvnc tightvnc-server sudo yum install tightvnc-server # 要先裝tightvnc-server sudo yum install xrdp # 再裝xrdp -- sudo repoquery -l xrdp # 查套件安裝哪些檔案 sudo rpm -ql /usr/bin/Xvnc # 查檔案所屬套件 -- cat /etc/xrdp/startwm.sh # 確認系統裝有如下任一種視窗管理程式 SESSIONS="gnome-session blackbox fluxbox startxfce4 startkde xterm" -- 啟動服務 sudo service xrdp status # 詢問xrdp服務狀態 sudo service xrdp start # 啟動xrdp服務 -- 測試連線 sudo netstat -antup | grep xrdp # 觀看是否3389及3350連接埠有監聽服務 註: 若連線過程,顯示訊息,缺權限,可如下給予selinux權限 sudo chcon --type=bin_t /usr/sbin/xrdp sudo chcon --type=bin_t /usr/sbin/xrdp-sesman -- rdp連線過程,適用於 CentOS 6.10 (1) xrdp (3389) # 選擇 sesman-Xvnc 模式 (2) xrdp-sesman (3350,root) (3) xrdp-chansrv # 執行 /etc/xrdp/startwm.sh 及 gnome-session (4) Xvnc (59xx) 註: 若為舊 CentOS-6,因自2020/11/30已不再提供維護更新,故須更新repo來源,如下: sudo rm CentOS-SCLo-scl* sudo curl https://www.getpagespeed.com/files/centos6-eol.repo --output /etc/yum.repos.d/CentOS-Base.repo sudo curl https://www.getpagespeed.com/files/centos6-epel-eol.repo --output /etc/yum.repos.d/epel.repocurl \ https://www.getpagespeed.com/files/centos6-epel-eol.repo --output /etc/yum.repos.d/epel.repo sudo yum update # 更新到6.10版 參考: 阿吉的部落格: 使用 xrdp 遠端登入 Linux (Gentoo)

how to clone the conda environment from a path?

執行 Python 語言由於程式的套件相依性很強,稍微不同版本套件可能程式就跑不起來。
因此,常須鎖定安裝特定套件版本,建置成一個程式專用執行環境。

常見的 Anaconda 軟體提供 Python環境管理功能,在Ubuntu等Linux作業系統上,
其管理程式 conda 一般安裝路徑為 /usr/local/anaconda3/bin/conda。

Linux作業系統上,用戶foobar的conda環境安裝路徑一般位於其家目錄,如下:

   /home/foobar/.conda/envs/

此時,利用 conda env list 指令,可列出家目錄下有多少環境。

假設用戶因空間問題,由管理者已將家目錄設定成新路徑 /home2/foobar/。
這時,為免重建執行環境的麻煩,可用如下指令為環境myenv拷貝一份到新家目錄。

   conda create --clone /home/foobar/.conda/envs/myenv --name myenv

其效果等同於將舊家目錄環境

   /home/foobar/.conda/envs/myenv/

拷貝一份到新家目錄

   /home3/foobar/.conda/envs/myenv/
   
拷貝後,同樣可利用 conda env list 指令,列出新家目錄下是否有 myenv 環境。

chlorine gas uses sigma p or sigma sp3 bonding?

ⅦA氟族氯氣(Cl₂)分子由兩顆氯原子(Chlorine)以單鍵,即σ鍵結合而成。每顆氯原子其原子序17,電子組態[Ne] 3s²3p⁵,最外殼層有7個價電子,其中6個成對,1個未成對。根據八隅體規則(Octet Rule),將兩個氯原子的未成對電子重疊共用,讓每個氯原子周圍有8個價電子時,氯氣分子可達到最大穩定度。對於氯氣的σ鍵組成是σp-p或σsp3-sp3混成軌域(hybridized orbitals),目前兩種說法都有支持者如下。

  1. σp-p: 依據兩個p軌域未成對電子重疊共用,可形成八隅體穩定現象,而支持氯氣的σ鍵組成是σp-p的說法有
    Chemistry - Molecular Structure (27 of 45) Sigma(p-p) Bond - Example。
  2. σsp3-sp3: 依據價殼層電子對互斥理論(VSEPR, Valence Shell Electron Pair Repulsion Theory),氯原子周圍空間位數(Steric Number)=鍵結數1+孤電子對數3=4,而支持氯氣的σ鍵組成是σsp3-sp3的說法有
    Hybridization of Cl2 (description of hybrid orbitals for Chlorine)。

由於兩者預測的分子形狀都是直線形,故無法由預測形狀區別,只能期待由實驗獲得的鍵長或鍵強度判定。相關的ⅦA氟族、ⅥA氧族、或VA氮族氣體分子應該也有類似的σ鍵組成疑問待證實。

how to manage self-select user groups on moodle

使用Moodle教學平台,如果想讓同學自由分組,有兩種作法。第一種是使用外加的Group self-selection module模組,操作較簡便,但此非預設模組,須請Moodle管理者安裝才能用此分組活動。第二種是從預設模組手動管理,操作較麻煩,但可利用現有票選(Choice)活動達成,不失為可行的替代方案。以下將介紹第二種手動管理法。

1. 開啟【票選(Choice)】活動C,設定截止期限之前,允許學生自由變更組別。
   假設想分成 N=10 組,每組人數上限 M=5 人,則可規劃
     team00, team01, team02, ..., team10, team11, team12, team13, team14, team15共16組。
   其中,team00為教師,助教群組,供了解學生操作畫面。team01 ~ team10為實際10個分組。
       team11 ~ team15為備用分組,供臨時拆分組暫存之用。
   活動的選項設定如下:
     是否允許變更選擇: 是
     允許選擇一個以上的選項: 否
     限制回答的次數: 否
      選項1: team00, 限制1: 2
      選項2: team01, 限制2: 6
      .....
      選項16: team15, 限制16: 6
   其中,限制人數上限為M+1=6,供緩衝之用。最終仍可要求每組M=5人。

2. 匯出 票選活動的分組結果 成為 外部分組名單檔案
   進入【票選(Choice)】活動C,點選【查看?個回應/以Excel檔案格式下載】。
   打開C.xlsx檔案,可看到同學自由分組結果,如下。
      學號    名字    學號   分組      選擇 {$a}
      rrrrr   nnnn   rrrr   team07    team07
      .....
   其中,【分組】欄為學生目前所屬組別,【選擇{$a}】欄為學生選取組別。
   兩者相同表示學生沒打算變動組別,兩者不同表示學生想變動組別。
   留下【學號】及【選擇 {$a}】兩欄位,整理成如下分組匯入格式,存成外部C.csv檔
      username, group
      學號1, team01
      學號2, team01
      .....
      學號n, team02

3. 批次匯入 外部分組名單檔案 成為 課程分組名單
   點選【系統管理/課程管理/用戶/匯入學生名單:】
    檔案位置:選擇一檔案,C.csv
    CSV分隔符號: ,
    編碼: UTF-8
    Role to assign: 學生
    First column contains: Id number
    Create group(s) if needed: 是
    Create grouping(s) if needed: 否 ** (新分組是否獨立為新分群)
    Send me a mail report: 否
    點選【加入課程】
    ---
    username xxx already enroled and added to Moodle's group team yy
    .....
    0 enroled
    zz group(s) created : team01, team02, ...
    tt grouping(s) created :

4. 產生 分組摘要表 供確認
   點選【系統管理/課程管理/用戶/分組/概要】,將摘要表拷貝到專屬頁面供學生確認。

5. 若想局部修正 分組名單,可修改C.csv檔,依步驟3.重新匯入。
   或點選【系統管理/課程管理/用戶】,由分組/成員/新增移除使用者,增減分組成員。

6. 取得最後課程設定好的 分組名單
   可重複步驟2,再次利用【票選(Choice)】活動C,匯出名單C.xlsx。
   留下其中的【學號】及【分組】兩欄位即可。

以上步驟3,用檔案批次匯入名單的角色非常關鍵,可免去步驟5,點選逐一加入名單的辛勞。

參考: 
1. [Moodle 2.6-2.8] How to download the list of participants with groups in a course
2. Blog: moodle administration memo

how to add a user with quota limit on ubuntu?

於Ubuntu作業系統想手動新增用戶,可利用如下adduser指令。

#################################
# add user with a login name of user_name
###################
$sudo adduser  --home=/home/user_name  user_name
正在新增使用者 `user_name' ...
增加新群組 `user_name' (10xx) ....
正在新增新使用者 `user_name' (UID 10xx) 到群組 `user_name' ....
正在新增家目錄 `/home/user_name' ...
正在從 `/etc/skel'複製檔案 ...
輸入新的 UNIX 密碼:
再次輸入新的 UNIX 密碼:
passwd: 密碼已成功地變更
正在改變 user_name 的使用者訊息
請輸入新值,或直接按 ENTER 鍵以使用預設值
	全名 []: user full name
	房間號碼 []:
	工作電話 []: phone
	住家電話 []:
	其它 []:
以上輸入的資料正確嗎? [Y/n] Y


#################################
# confirm user profile of user_name
##################
$ grep user_name /etc/passwd
user_name:x:10xx:10xx:user full name,,phone,:/home/user_name:/bin/bash


#################################
# assume quota limit of source_user is 
#        Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
#      /dev/sdyy      zz         30000000 100000000              13       0       0
# copy disk quota limit settings of source_user to user_name
##################
$sudo edquota -p  source_user   user_name


################################
# confirm disk quota limit
#   blocks: usage of data blocks
#   quota:  soft limit of data blocks
#   limit:  hard limit of data blocks
#   grace:  grace period when soft limit of data blocks is exceeded
#   --
#   files:  usage of inode blocks
#   quota:  soft limit of inode blocks
#   limit:  hard limit of inode blocks
#   grace:  grace period when soft limit of inode blocks is exceeded
#   --
#   when grace period is exceeded, no further writing to disk is allowed 
#     until usage is reduced below soft limit
##################
$sudo quota -u user_name
Disk quotas for user user_name (uid 10xx):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdyy      60  30000000 100000000              13       0       0

rdp port is not listening when using xrdp

Ubuntu等Linux系統可以透過xrdp軟體監聽tcp rdp (3389)埠號,接受Windows mstsc遠端桌面客戶端連線。
一旦發現3389埠號無法連線,可以如下進行診斷:

1.檢查3389埠號是否有行程監聽
  $ sudo lsof -i :3389
  COMMAND   PID USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
  xrdp    12345 xrdp    6u  IPv4 257547474      0t0  TCP *:3389 (LISTEN)

  $ sudo ss -tulpn | grep 3389
  tcp    LISTEN     0      2         *:3389                  *:*                   users:(("xrdp",pid=12345,fd=6))

2.重新啟動xrdp服務
  $ sudo rm /var/run/xrdp/xrdp.pid    # 刪除舊行程記錄,才能重啟服務
  $ sudo service xrdp restart         # 舊重啟方法
  $ sudo systemctl restart xrdp       # 新重啟方法

how to use the piclayer plugin in josm for map making

開放街圖常用 JOSM 軟體當作其 Java 版圖資編輯器。用 JOSM 標示設施時,有時須要參考相關圖片,例如景點空拍圖或官方設施圖等,疊圖以確定其位置。這時可安裝 piclayer 外掛,將這些圖片放進 JOSM 圖層,挑選其中幾個顯眼目標,透過平移、縮放、旋轉等操作,和開放街圖作對齊,以利針對景點相關設施位置,進行標示作業。

以下以修改故宮至善園的標示為例作說明。

0a.預先將景點設施圖以螢幕擷圖貼到小畫家存成【至善園.png】圖檔,如下:
0b.點選【編輯/偏好設定】,如下:
0c.點選【外掛/搜尋】輸入 piclayer,按【OK】,開始安裝 piclayer 外掛,如下:
1a.點選【圖磚/來自檔案的新相片圖層】,如下:
1b.點選預先擷取好的【至善園.png】圖檔,放進新圖層,命名為【至善園.png】圖層,如下:
2.點選【至善園.png】圖層為作用圖層,利用左側piclayer工具欄的平移、旋轉、縮放按鈕,操作圖層的圖片, 挑選其中幾個顯眼目標,將疊圖和底層圖資校正對齊。範例中的圖層由上而下依序顯示(visible)如下, 最上層為【至善園.png】圖層,透明度 < 50%, 中間層為【nlsc_wms_2019EMAP98】臺灣通用電子地圖(新),透明度 < 50%, 最底層為【nlsc_wms_2019PHOTO2】正射影像圖(通用)
3.點選【資料圖層1】圖層為作用圖層,顯示開放街圖向量圖資,利用左側開放街圖工具欄,開始修改設施位置及標示。
4.點選【檔案/上傳資料...】,上傳圖資更新集。稍後重新載入,即可得到新版至善園開放街圖,如下:
    註解
  1. 如何於JOSM載入臺灣通用電子地圖(新)及正射影像圖(通用)圖磚,可參考「how to show NLSC taiwan maps on JOSM」說明。
  2. 對於扭曲不大,或水平/垂直軸比例一致的圖片,piclayer 外掛允許操作左側工具欄的平移、旋轉、縮放三顆按鈕,將圖片校正對齊底圖; 對於扭曲較大,或水平/垂直軸比例不一致的圖片,piclayer 外掛也允許操作左側工具欄的綠色右上箭頭按鈕。先於圖片以圓圈標示3處檢查點, 再操作左側工具欄的紅色右上箭頭按鈕,分別對準圓圈正中央,移動檢查點和底圖對應位置重疊。 如此不斷修正圖片和底圖的3處檢查點對應關係,試著以仿射變換,將圖片校正對齊底圖,過程如「Using PicLayer plugin in JOSM...」YouTube範例所示。

no menu after xrdp to ubuntu

Ubuntu可以安裝xrdp遠端桌面服務,利用Microsoft Terminal Service Client (mstsc.exe)遠端桌面登入。
登入之後,會開啟如下桌面相關行程,假設所用為xfce4輕量級桌面:
  /bin/sh /etc/X11/Xsession
  /usr/lib/xorg/Xorg :xx -auth .Xauthority -config xrdp/xorg.conf -noreset -nolisten tcp -logfile .xorgxrdp.%s.log
  /usr/sbin/xrdp-chansrv
  xfce4-session
  /usr/lib/x86_64-linux-gnu/xfce4/xfconf/xfconfd
  xfwm4
  xfdesktop
  xfsettingsd
  xfce4-panel

如果初次登入之後,只見螢幕中有一塊黑色空白(blank black)面板,卻看不到其他軟體選單。
這時,可對著黑色空白面板按下滑鼠右鍵,如下:


從跳出的右鍵選單中,點選「面板偏好設定(E)...」。
或從終端機,利用 xfce4-panel -p 指令,進入「面板偏好設定(E)...」,如下


從跳出的面板選單中,點選「Backup and restore」備份及復原,如下。

若沒有「Backup and restore」備份及復原可點選,可自行按綠色+,增添新面板,
再於新面板的項目(M),按綠色+,為面板新添「Applications Menu」項目,獲得應用程式選單鈕。

執行 xfpanel-switch,從跳出的Xfce面板切換器中,點選「Xfce 4.12」組態,再按下齒輪套用按鈕,如下:


即可順利回復螢幕上方軟體列(Applications Menu)及下方快速列(Shortcut Menu)兩面板選單,如下:

json format for ChineseQA-with-BERT

正常解問答題時,常以1文章1問題1答案為單位進行,但準備資料集時為省空間,常依實際1文章多問題多答案格式來存放案例。 故在利用底層BERT(雙向變形器編碼表現法)微調模型及預測問答時,須將1文章多問題多答案資料,還原成1文章1問題1答案格式, 才能進行微調及預測。

百度ChineseQA-with-BERT套件可基於BERT預訓練模型作問答題微調。 其run_dureader.py可接受的訓練檔json格式,可用來存放1文章1問題1答案內容,或1文章多問題多答案內容。

其中,訓練案例的各欄位路徑如下:

․問題編號: data/paragraphs/qas/id
․文章: data/paragraphs/context
․問題: data/paragraphs/qas/question
․答案: data/paragraphs/qas/answers/text

以下舉例說明此格式用來存放1文章1問題1答案的json格式長相。
{
    "data": [
        {
            "paragraphs": [
                {
                    "context": "文章",
                    "qas": [
                        {
                            "answers": [
                                {
                                    "answer_start": 答案起點下標,
                                    "text": "答案"
                                }
                            ],
                            "is_impossible": false,
                            "id": 問題編號,
                            "question": "問題"
                        }
                    ]
                }
            ],
            "title": "N.A."
        }
   ]
}

how to call Java classes in a web page by cheerpj

🚀 在瀏覽器中直接執行 Java:CheerpJ v3 實作指南 長期以來,Java Applets 因為安全性與插件問題早已退出歷史舞台。但隨著 WebAssembly (Wasm) 技術的成熟,現在網頁安裝如下 CheerpJ v3 套件庫,就可以在瀏覽器中直接呼叫 ...

總網頁瀏覽量