Jack's Blog

流淌的心,怎能阻拦,吹来的风,又怎能阻挡。

实验二

一. 实验目的

1. 掌握自定义类的创建和使用等操作

2. 掌握 matplotlib 模块的使用

二. 实验内容

文件UN.txt中存放193个联合国成员信息,每行包括一个国家的名称、所在大洲、人口(百万)和面积(平方英里),例如:

Canada,North America,34.8,3855000
France,Europe,66.3,211209
New Zealand,Australia/Oceania,4.4,103738
Nigeria,Africa,177.2,356669
Pakistan,Asia,196.2,310403
Peru,South America,30.1,496226

(a) 创建一个Nation类包括四个实例变量存储国家信息和一个名为pop_density方法计算一个国家的人口密度。用这个类编写一个程序包含193个词条的字典。每个词条形式如下:

name of a country: Nation object for that country

用文件UN.txt创建这个字典,将这个字典保存到一个名为nationsDict.dat的永久二进制文件中,同时将Nation类保存到nation.py文件中。

(b) 利用nationsDict.dat和nation.py文件编写一个程序(search.py),输入联合国成员国名字,显示这个国家所有信息。如:

Enter a country: Canada
Continent: North America
Population: 34,800,000
Area: 3,855,000.00 square miles

(c) 利用nationsDict.dat和nation.py文件编写一个程序(sort.py),输入一个大洲的名字,按照降序使用 matplotlib 的柱状图功能画出该大洲人口密度前10名的联合国成员国名字及对应的人口密度。

将文件 nationsDict.dat,nation.py,search.py,sort.py 打包上传,压缩文件命名为:学号_姓名_实验2

nation.py

import pickle
class nation:
       def __init__(self, name='', continent='', pop='', area='', pop_density=''):
               self._name = name
               self._continent = continent
               self._pop = pop
               self._area = area
               self._pop_density =pop_density

       def setName(self, name):
               self._name = name

       def setContinent(self, continent):
               self._continent = continent

       def setPop(self, pop):
               self._pop = pop

       def setArea(self, area):
               self._area = area

       def getName(self, name):
               return self._name

       def getContinent(self, continent):
               return self._continent

       def getPop(self, pop):
               return self._pop

       def getArea(self, area):
               return self._area

       def pop_density(self):
               return (self._pop / self._area)
       def __str__(self):
               return ("The poplation density of" + str(self._name) + "is" + str(self.pop_density()))


f = open('UN.txt')
dict = {}
for line in f:
         words = line.split(",")
         _nation=nation(continent='', pop='', area='', pop_density='')

         _nation.setName(words[0])
         _nation.setContinent(words[1])
         _nation.setPop(words[2])
         _nation.setArea(words[3])
         dict[words[0]] = _nation

outfile = open("nationsDict.dat",'wb')
pickle.dump(dict,outfile)
outfile.close()

search.py

import pickle
import nation

def getDictionary(fileName):
    infile = open(fileName, 'rb')
    nations =pickle.load(infile)
    infile.close()
    return nations

def inputNameOfNation(nations):
    nation = input("Input a name of a UN member nation: ")
    while nation not in nations:
        print("Not a member of the UN.Please try again.")
        nation = input("Input a name of a UN member nation: ")

def displayData(nations,nation):
    print("Continent:", nations[nation]['continent'])
    print("Populaton:",nations[nation]['pop'], "million people")
    print("Area:",nations[nation]['area'],"square miles")

nations = getDictionary("nationsDict.dat")
nation = inputNameOfNation(nations)
displayData(nations,nation)

sort.py

import matplotlib.pyplot as plt
import nation
import pickle
def getDictionary(fileName):
    infile = open(fileName, 'rb')
    nations =pickle.load(infile)
    infile.close()
    return nations
nations = getDictionary("nationsDict.dict")
for i in nations[i]:
    nation.pop_density()

nation.pop_density.sort

plt.bar(data['x'], data['y'])


不建议任何人直接复制此代码

如果你是哈尔滨工业大学学生,请你一定不要复制此代码。因为此代码已被输入查重系统,一旦查重率超过20%,将会被认为抄袭。

此实验会为0分

cd /usr/share/applications/
vim Pycharm.desktop //如果没有此文件,可以新建一个.
	
[Desktop Entry]
Type=Application
Name=Pycharm
GenericName=Pycharm3
Comment=Pycharm3:The Python IDE
Exec=sh /sdb/python/pycharm-2016.2.3/bin/pycharm.sh  //修改为你的地址
Icon=/sdb/python/pycharm-2016.2.3/bin/pycharm.png    //修改为你的地址
Terminal=pycharm
Categories=Pycharm;

我这个例子是给pycharm创建一个快捷方式。

给其他应用程序创建快捷方式,只需照猫画虎即可。

#!/usr/bin/env xdg-open

[Desktop Entry]
Categories=Development;
Comment[zh_CN]=
Comment=
Exec=/home/obaby/soft/pycharm-2016.1/bin/pycharm.sh %f
GenericName[zh_CN]=IDE
GenericName=IDE
Icon=/home/obaby/soft/pycharm-2016.1/bin/pycharm.png
MimeType=
Name[zh_CN]=PyCharm
Name=PyCharm
Path=
StartupNotify=true
Terminal=false
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=obaby

上面是另一个人给的kde桌面的代码。

其实都是一个道理

如何在Fedora 25上安装pip 3

wget https://bootstrap.pypa.io/ez_setup.py

#安装easy_install-3.5
python3.5 ez_setup.py

#安装完成后/usr/local/bin/目录下出现easy_install-3.5

#安装pip3.5
easy_install-3.5 pip

#安装完成后/usr/local/bin/目录下出现pip3.5

#升级pip3.5版本
pip3.5 install --upgrade pip

一般程序的手动编译安装

阅读全文

由于某些安全性的原因fedora 取消了图形化界面添加su

因而只能采取后台操作添加将自己添加为su

不少freshman(包括我)都是摸索了好长时间才学会的

下面分享方法

su #输入密码后得到root权限
visudo
a #进入append模式(系统会显示INSERT)

在文件中找到这样的代码

## Allow root to run any commands anywhere
root ALL=(ALL) ALL

然后在其下面添加一行

your_name ALL=(ALL) ALLyour_name ALL=(ALL) ALL #your_name 为你的用户名

然后

按Esc 
输入“:w”(保存文件) 
输入“:q”(退出) 

FAQ

1.我的用户名在哪里可以看到?

在终端的开头[your_user_name@...]

2.在编辑文件的时候系统提示我语法错误

只要按照本操作,输入Q后便可保存并退出了

最后便可以愉快的使用sudo了

索引概论笔记

阅读全文

Before we go

16年安装了fedora 25,然而由于学校的各种事情,用windows还是比较方便。感到遗憾的是一直没有很好的利用这么好的资源,包括各种开源的软件和强大的环境友好性。

现在我想将自己的工作平台全部转移到Fedora 25上,有几大配置非常有用,我将把他们分享给大家


1.Pycharm edu

自行搜索其官网下载最新版的 pycharm edu 最新版

  1. Unpack the PyCharm Edu distribution archive that you downloaded to
     where you wish to install the program. We will refer to this destination
     location as your {installation home} below.

  2. Open a console and cd into "{installation home}/bin" and type:

       ./pycharm.sh

     to start the application. As a side effect, this will initialize various
     configuration files in the ~/.PyCharmEdu3.5 directory.

  3. [OPTIONAL] Add "{installation home}/bin" to your PATH environment
     variable so that you may start PyCharm Edu from any directory.

  4. [OPTIONAL] To adjust the value of the JVM heap size, create
      ~/.PyCharmEdu3.5/pycharm.vmoptions (or pycharm64.vmoptions
      if using a 64-bit JDK), and set the -Xms and -Xmx parameters. To see how
      to do this, you can reference the vmoptions file under
      "{installation home}/bin" as a model.

  [OPTIONAL] Changing the location of "config" and "system" directories

2.python 3

下载地址:https://www.python.org/downloads/release/python-361/

安装代码:

On Unix, Linux, BSD, macOS, and Cygwin::

    ./configure
    make
    make test
    sudo make install

3.搜狗输入法

安装fedora 中文软件源

$ sudo dnf config-manager --add-repo=http://repo.fdzh.org/FZUG/FZUG.repo 
$ sudo dnf install fzug-release -y
$ sudo dnf install sogoupinyin sogoupinyin-selinux -ysudo dnf install sogoupinyin sogoupinyin-selinux -y
$ reboot

该包已添加 fcitx-gtk2, fcitx-gtk3, fcitx-qt4 和 fcitx-qt5 模块依赖。
注意:由 iBus 切换至 Fcitx 需要 重启/注销 系统,以便 imsettings 启动相应输入法。

FAQ

使用 Sogou Pinyin

如果您使用 XDG 兼容的桌面环境,比如 KDE, GNOME, XFCE, LXDE, Cinnamon。那么当您安装好 Sogou 并重新登录后,Fcitx 和 Sogou 应该会自动启动。使用 Ctrl+Space 激活 Fcitx 便可以输入了,Shift 临时切换中英文。

1). sogou-qimpanel 未自动启动

如果 Fcitx 没有随桌面环境自动启动,请检查 imsettings 设置,正常的配置如下所示:

$ imsettings-info 
Xinput file: /etc/X11/xinit/xinput.d/fcitx.conf
GTK+ immodule: fcitx
Qt immodule: fcitx
XMODIFIERS: @im=fcitx
XIM server: /usr/bin/fcitx -D
Preferences: /usr/bin/fcitx-configtool
Auxiliary:
Short Description: FCITX
Long Description:
Icon file: /usr/share/pixmaps/fcitx.png
Is system default: TRUE
Is user default: TRUE
Is XIM server: FALSE
$ imsettings-switch fcitx  # 切换至 fcitx

如果您的桌面环境不兼容 XDG,则 sogou-qimpanel 不会自动启动。请使用桌面环境自带的自动启动工具,添加 sogou-qimpanel 启动项。

如果您的桌面环境不包含自启动工具,或您使用 startx 脚本启动图形界面,则在 ~/.profile 中添加以下命令。

$ vim ~/.profile
source /etc/sysconfig/sogoupinyin

该脚本在启动 X 时被 /etc/X11/xinit/xinitrc-common 调用,用于设置 Fcitx 环境变量,并启动 sogou-qimpanel

2). 如何安装皮肤

查看帮助信息:

$ rpm -qi sogoupinyin
皮肤保存在~/.config/sogou-qimpanel/skin/, 按以下方式安装:
  $ sudo setsebool sogou_enable_homedirs=1
  $ sogou-qimpanel Skin.ssf

3). 如何安装词库

查看帮助信息:

$ rpm -qi sogoupinyin
词库保存在~/.config/SogouPY/scd/, 按以下方式安装:
  $ sudo setsebool sogou_enable_homedirs=1
  $ sogou-qimpanel Cell.scel

4). 禁止 Sogou 访问网络

查看帮助信息:

$ rpm -qi sogoupinyin
禁止 sogou 访问网络:
  $ sudo setsebool -P sogou_access_network=0 # 默认: true

5). 小黑框问题

Xfce 桌面环境,如遇到小黑框,需开启 Compositor 功能:

Settings -> Windows Manger Tweaks -> Compositor
设置 -> 窗口管理器微调 -> 合成器

Mate 桌面环境,如遇到小黑框,需开启 Compositor 功能:

System -> Control Center -> Windows -> Enable software composit..

LXDE 桌面环境,如遇到小黑框,需要修改窗口管理器。

$ yum install compiz-lxde ccsm
$ vim ~/.config/lxsession/LXDE/desktop.conf
 window_manager=openbox  # 原参数
 window_manager=compiz-lxde-emerald  # 修改为

6). GTK/Qt 程序无法切换输入法

如果遇到无法切换输入法,则检查 Fcitx 环境变量 是否已正确设置。

$ env | grep fcitx
GTK_IM_MODULE=fcitx
QT4_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx

对于兼容 XDG 的桌面环境,Fcitx 环境变量应由 imsettings 通过 /etc/X11/xinit/xinputrc 配置。

$ ll /etc/X11/xinit/xinputrc
/etc/X11/xinit/xinputrc -> /etc/alternatives/xinputrc

7). 选词框乱码

如果您碰到了 #79 的问题。可能是您启用了 "轻量界面 (fcitx-ui-light)" ,它会导致 sogou-qimpanel 不能正常显示。在 "输入法配置" -> "附加组件" 中,禁用 "轻量界面" 即可。

PS: 源里的 fcitx-cloudpinyin 可以正常使用 Google 云拼音,有了云拼音 libpinyin 之类的输入法也挺好,内存占用低。

故障排除

  • imsettings:根据 ~/.cache/imsettings/log 日志排查错误
  • Fcitx:运行 fcitx-diagnose 排查 Fcitx 错误
  • Sogou:运行 sogou-diag 收集诊断信息

参考:https://github.com/FZUG/repo/wiki/Sogou-Pinyin-%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98

4.安装中文软件包源

软件包列表

按 Fedora 版本浏览


Name Lisence Require repo Description
Input Methods
sogoupinyin Proprietary, GPLv2 fedora 搜狗拼音输入法
fcitx-rime GPLv3 fedora 中州韵输入法
fcitx-sunpinyin GPLv2+ fedora sunpinyin 输入法
fcitx-qt5 GPLv2 fedora fcitx qt5 输入模块
Multimedia
kwplayer GPLv3 rpmfusion 酷我音乐
doubanfm-qt MIT rpmfusion 豆瓣FM
musicbox MIT rpmfusion 网易云音乐 CLI
deepin-music-player GPLv3 rpmfusion 深度音乐
moonplayer GPLv3 rpmfusion Moonplayer播放器
simplescreenrecorder GPLv3 rpmfusion 屏幕录像
obs-studio GPLv2 rpmfusion 屏幕录像/流媒体直播
tragtor LGPLv2 rpmfusion FFmpeg音视频转码
Notes / Dict
wiznote GPLv3 fedora 为知笔记 stable
wiznote-beta GPLv3 fedora 为知笔记 beta
youdao-dict Proprietary fedora 有道词典 for linux
Browser / Proxy
opera-developer Proprietary fedora Opera developer
opera-beta Proprietary fedora Opera beta
opera-stable Proprietary fedora Opera stable
freshplayerplugin MIT fedora Firefox PPAPI flash 兼容插件
Downloads
bcloud GPLv3 fedora 百度云客户端
xware-desktop GPLv3 fedora 迅雷客户端
pointdownload GPLv3 fedora 点载, 支持迅雷/BT/ed2k下载
System tools
ccal LGPL fedora 命令行下的农历日历
grub4dos GPLv2 fedora grub 引导管理器
screenfetch GPLv3 fedora 系统信息收集
vim 7.4.764 vim fedora 编辑器之神,增加剪贴板/lua/py3支持
dkms-mt7601u GPL fedora MT7601U USB Wifi 驱动
System libraries
opencc ASL2 fedora 简繁转换库,修正依赖
sunpinyin LGPLv2 fedora 基于 SLM 模型的输入法引擎,更新字典
python-html2text GPLv3 fedora HTML -> ASCII
python3-xlib GPLv2 null Python3 X 库
python3-keybinder GPLv3 null Python3 键绑定库
python-mutagen GPLv2 fedora 处理音频元数据
python3-cairo LGPLv2 fedora Python3 cairo 绑定,修复 bug
pygobject3 LGPLv2+ fedora Python GObject 封装,修复 bug
deepin-ui GPLv3 fedora Deepin UI toolkit
deepin-utils GPLv3 fedora Deepin utils 库
deepin-gsettings GPLv3 fedora gsettings python 绑定
pyjavascriptcore GPLv3 fedora

pyjs

在我们安装完中文软件源后就可以安装很多软件,只需:

dnf install *(相应软件名称)

 

5.安装python 的依赖库

大家在运行python时,肯定不想被缺乏相应的函数库而困扰

我查阅了相应的资料,只需:

 

pip3 install turtle(for example)pip install turtle(for example)
pip install upgrade pip

pip 是Python通用的

而pip 3 是专门为python 3 开发的

6.googel chrome

cat << EOF > /etc/yum.repos.d/google-chrome.repo
[google-chrome]
name=google-chrome - \$basearch
baseurl=http://dl.google.com/linux/chrome/rpm/stable/\$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
EOF
dnf install google-chrome-stable
dnf install google-chrome-beta

Note for Fedora 26/25 Wayland users

If you have problems, then fallback to Xorg with modifying /etc/gdm/custom.conf file:# GDM configuration storage

[daemon]
# Uncoment the line below to force the login screen to use Xorg
WaylandEnable=false

[security]
...

Python--倒排索引

一.       实验目的

  1. 掌握列表、集合和字典的定义、赋值、使用等基本操作,熟悉处理复杂数据类型的一般流程
  2. 熟悉列表、集合和字典的常用函数和技巧
  3. 考察对文本的灵活处理和对排序算法的运用

二.       实验内容

倒排索引(Inverted index),也常被称为反向索引,是一种索引方法,用来存储某个单词存在于哪些文档之中。是信息检索系统中最常用的数据结构。通过倒排索引,可以根据单词快速获取包含这个单词的文档列表。

本实验主要完成以下三个功能:

(1). 建立索引:首先输入100行字符串,用于构建倒排索引,每行字符串由若干不含标点符号的、全部小写字母组成的单词构成,每个单词之间以空格分隔。依次读入每个单词,并组成一个由<单词, 每个单词出现的行号集合>构成的字典,其中行号从1开始计数。

(2). 打印索引:按照字母表顺序依次输出每个单词及其出现的位置,每个单词出现的位置则按行号升序输出。例如,如果“created”出现在第3, 20行,“dead”分别出现在14, 20, 22行。则输出结果如下(冒号和逗号后面都有一个空格,行号不重复):

created: 3, 20

dead: 14, 20, 22

(3). 检索:接下来输入查询(Query)字符串,每行包含一个查询,每个查询由若干关键字(Keywords)组成,每个关键字用空格分隔且全部为小写字母单词。要求输出包含全部单词行的行号(升序排列),每个查询输出一行。若某一关键字在全部行中从没出现过或没有一行字符串包含全部关键字,则输出“None”。遇到空行表示查询输入结束。如对于上面创建的索引,当查询为“created”时,输出为“3, 20”;当查询为“created dead”时,输出为“20”;当查询为“abcde dead”时,输出为“None”;

(4). 高级检索:当输入的Query以“AND:”开始,则执行“与”检索,即要求输出包含全部关键字的行;如果输入的Query以“OR:”开始,则执行“或”检索,即某行只要出现了一个关键字就满足条件。默认情况(不以“AND:”或“OR:”开始),执行“与”检索。

依次完成以上功能(提交程序命名:“学号_姓名_5.py”)


以下是代码

     #'''''Part 1 : Setup index'''  
      
    dict = {} # a emtry dictionary.  
    n = 100  
    for row in range(0,n):    
      
        information = raw_input()  
          
        line_words = information.split()   
        # split the information inputed into lines by '/n'  
      
        for word in line_words : # Judge every word in every lines .         
      
            # If the word appear first time .  
            if word not in dict :  
                item = set()   # set up a new set .  
                item.add(row+1)  # now rows  
                dict[word] = item   # Add now rows into keys(item).  
      
            # THe word have appeared before .  
            else:     
                dict[word].add(row+1)    # Add now rows into keys(item).  
      
    # print dict    we can get the information dictionary.  
      
                  
    '''''Part 2 : Print index'''   
      
    word_list = dict.items()  # Get dict's items .  
      
    word_list.sort( key = lambda items : items[0] ) # Sort by word in dict.  
      
    for word , row in word_list : # Ergodic word and row in word_list .  
          
        list_row = list(row)  
        list_row.sort()  
      
        # Change int row into string row .  
        for i in range ( 0 , len(list_row) ):  
            list_row[i] = str(list_row[i])  
          
        # print result the part 2 needed .  
        print word + ':' , ', '.join(list_row)  
      
      
    ''''' Part 3 : Query '''  
    # define judger to judger if all querys are in dict.  
    def judger(dict , query):  
        list_query = query.split()  
        for word in list_query :  
            if word not in dict :  
                return 0    # for every query ,if there is one not in dict,return 0  
        return 1   # all query in dict .  
      
    query_list = []   
      
    # for input , meet '' ,stop input.  
    while True:  
        query = raw_input()  
        if query == '' :  
            break     
        elif len(query) != 0 :  
            query_list.append(query) # append query inputed to a list query_list .  
      
      
    # Ergodic every query in query_list.       
    for list_query in query_list :  
          
        # if judger return 0.  
        if judger(dict , list_query) == 0 :  
            print 'None'  
        
        else:  
            list_query = list_query.split()  
            query_set = set()  # get a empty set  
              
            # union set to get rows .  
            for isquery in list_query :  
                query_set = query_set | dict[isquery]  
             
            # intersection to get common rows .  
            for isquery in list_query :  
                query_set = query_set & dict[isquery]  
               
            # if intersection == 0   
            if len(query_set) == 0 :  
                print 'None'  
      
            else:  
                query_result = list(query_set)  
                query_result.sort()  
                for m in range(len(query_result)) :  
                    query_result[m] = str(query_result[m])  
                  
                print ', '.join(query_result)  

for python 3

word_dic = {}
line_len = 3

# 建立索引
for i in range(line_len):
    line = input()
    words = line.split()
    for word in words:
        if word in word_dic:
            word_dic[word].add(i+1)
        else:
            word_set = set()
            word_set.add(i+1)
            word_dic[word] = word_set

#打印索引
word_list = []
for word,word_set in word_dic.items():
    word_list.append((word,word_set))

for word,line in word_list:
   list_line = list(line)
   list_line.sort()
   for i in range(len(list_line)):
    list_line[i] = str(list_line[i])

    print(word + ': ' , ', '.join(list_line))

#检索与高级索引
def judger(dict , query):
    list_query = query.split()
    for word in list_query :
        if word not in dict :
            return 0
    return 1

query_list = []
while True:
    query = input()
    if query == '' :
        break
    elif len(query) != 0 :
        query_list.append(query)

    if judger(dict , list_query) == 0 :
        print('None')
    else:
        list_query = list_query.split()
        query_set = set()  # get a empty set
        for isquery in list_query :
            query_set = query_set | dict[isquery]
        for isquery in list_query :
            query_set = query_set & dict[isquery]
        if len(query_set) == 0 :
            print('None')

        else:
            query_result = list(query_set)
            query_result.sort()
            for m in range(len(query_result)) :
                query_result[m] = str(query_result[m])

            print(', '.join(query_result))

 

打造Java集成平台

1.JAVA SE

You can download this on the oracle webside.

2. JC

 需要注意的事项

•环境变量的配置
–java_home
•jdk的安装路径,
•例如:C:\Program Files\java\jdk1.8
–classpath
•java类文件的路径
•一般配置如下:
–.;%java_home%\lib\dt.jar; %java_home%\lib\tools.jar;
–path
•命令的搜索路径
•在原来的基础上增加:%java_home%\bin

3.eclipse

自己下载就好了