小编Mon*_*lal的帖子

使用正则表达式检测 R 中的数字重复

这段代码不应该适用于 R 中的重复数字检测吗?

> grep(pattern = "\\d{2}", x = 1223)
[1] 1
> grep(pattern = "\\d{3}", x = 1223)
[1] 1
Run Code Online (Sandbox Code Playgroud)

如果有 988,我们应该得到 true;如果有 123,我们应该得到 false。

听起来好像不是。

> grep(pattern = "\\d{2}", x = "1223")
[1] 1
> grep(pattern = "\\d{2}", x = "13")
[1] 1
Run Code Online (Sandbox Code Playgroud)

regex r

0
推荐指数
1
解决办法
1143
查看次数

初始化空值项时出现空指针异常

我想给一个名为State的类的每个子项赋值,而我有一个状态数组最初都为null,我在这里接收空指针引用:

//finding all the neighbor states of a given configuration

public State[] neighborStates(String config, int modeFlag){
    State[] neighborStates=new State[7];
    int i=0;
    for (Operation o : Operation.values()){
        neighborStates[i].config=move(config,o.name().charAt(0));
        neighborStates[i].realCost++;
        neighborStates[i].opSequence+=o.name();
        neighborStates[i].heuristicCost=getHeuristicCost(neighborStates[i].config, modeFlag);
        i++;
    }       

    return neighborStates;
}
Run Code Online (Sandbox Code Playgroud)

我将代码更改为此但我还是获得了NPE:

public State[] neighborStates(String config, int modeFlag){
        State[] neighborStates=new State[8];
        int i=0;
        for (Operation o : Operation.values()){
            neighborStates[i] = new State(move(config,o.name().charAt(0)),neighborStates[i].realCost++,
                                getHeuristicCost(neighborStates[i].config, modeFlag), neighborStates[i].opSequence+=o.name());
            //neighborStates[i].config=move(config,o.name().charAt(0));
            //neighborStates[i].realCost++;
            //neighborStates[i].opSequence+=o.name();
            //neighborStates[i].heuristicCost=getHeuristicCost(neighborStates[i].config, modeFlag);
            i++;
        }
Run Code Online (Sandbox Code Playgroud)

类State定义为:

public class State {
    public State(String config, int realCost, int heuristicCost, String …
Run Code Online (Sandbox Code Playgroud)

java null nullpointerexception

0
推荐指数
1
解决办法
70
查看次数

R中的数据清理

我有一个csv文件,我只想提取句子的时间戳,其中包含该句子中的水果名称.我怎么能在R中这样做(或者如果有更快的方法,那是什么?)

rosbagTimestamp,data
1438293900729698553,robot is in motion toward [strawberry]
1438293900730571638,Found a plan for avocado in 1.36400008202 seconds
1438293900731434815,current probability is greater than EXECUTION_THRESHOLD
1438293900731554567,ready to execute am original plan of len = 33
1438293900731586463,len of sub plan 1 = 24
1438293900731633713,len of sub plan 2 = 9
1438293900732910799,put in an execution request; now updating the dict
1438293900732949576,current_prediciton_item = avocado
1438293900733070339,current_item_probability = 0.880086981207
1438293901677787230,current probability is greater than PLANNING_THRESHOLD
1438293901681590725,robot is in motion toward [avocado]
1438293902689233770,we have received verbal request …
Run Code Online (Sandbox Code Playgroud)

csv r dataset data-cleaning

0
推荐指数
1
解决办法
287
查看次数

在 bash 中判断三角形是否等腰

当三角形为等腰三角形时,如何总结这段代码?

  1 #!/bin/bash
  2 
  3 read x y z
  4 
  5 if [[ x -eq z ]] && [[ x -eq y ]] && [[ y -eq z ]]; then
  6   echo EQUILATERAL
  7 elif [[ x -eq z ]] && [[ x -eq y ]]
  8 then
  9   echo ISOSCELES
 10 elif [[ y -eq z ]] && [[ y -eq x ]]
 11 then
 12   echo ISOSCELES
 13 elif [[ z -eq x ]] && [[ z -eq …
Run Code Online (Sandbox Code Playgroud)

bash shell if-statement sh

0
推荐指数
1
解决办法
6038
查看次数

ViewDoesNotExist在/

我收到以下错误:

ViewDoesNotExist at /
'<HttpResponse status_code=200, "text/html; charset=utf-8">' is not a callable or a dot-notation path
Request Method: GET
Request URL:    http://0.0.0.0:8000/
Django Version: 1.9.7
Exception Type: ViewDoesNotExist
Exception Value:    
'<HttpResponse status_code=200, "text/html; charset=utf-8">' is not a callable or a dot-notation path
Exception Location: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py in get_callable, line 102
Python Executable:  /Library/Frameworks/Python.framework/Versions/3.4/bin/python3
Python Version: 3.4.1
Python Path:    
['/Users/mona/interviews/django/learning_site',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/beautifulsoup4-4.3.2-py3.4.egg',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']
Server time:    Mon, 20 Jun 2016 13:18:23 +0000
Run Code Online (Sandbox Code Playgroud)

运行此命令时:

$ python3 manage.py  runserver 0.0.0.0:8000
Performing system …
Run Code Online (Sandbox Code Playgroud)

python django python-3.x

0
推荐指数
1
解决办法
528
查看次数

查找有效{}()[]的字符串

如何修复我的代码,以便找到有效的(){} []?现在,它只返回true.

public static boolean isValid(String s){

        HashMap<Character, Character> specialChar= new HashMap<>();
        specialChar.put('{', '}');
        specialChar.put('[',']');
        specialChar.put('(',')');
        Stack<Character> stk = new Stack<>();
        for (int i=0; i<s.length(); i++){

            if (specialChar.keySet().contains(s.charAt(i))){
                stk.push(s.charAt(i));
            }
            else if (specialChar.values().contains(s.charAt(i))){
                if (!stk.empty()) {
                    stk.pop();
                }
            }

        }

        return stk.isEmpty();

    }


 System.out.println(isValid("{}{lll}]"));
Run Code Online (Sandbox Code Playgroud)

java stack hashmap

-2
推荐指数
1
解决办法
104
查看次数

检测文本是否为非英语

检测文本(特别是Instagram评论)是非英语的最准确方法是什么?我很乐意使用任何高级语言,例如Python,PHP等.

$ sudo pip2 install guess_language
>>> from guess_language import guessLanguage
>>> guessLanguage('la vita e bella')
'UNKNOWN'
>>> guessLanguage('today is a good day')
'UNKNOWN'
>>> guessLanguage('????????????????(???)')
'ja'
Run Code Online (Sandbox Code Playgroud)

$ sudo apt-get install php5.6-mbstring

      if(strlen($comment->text) == mb_strlen($comment->text, 'utf-8')) {
         echo '- '.$comment->text."\n";
    }
Run Code Online (Sandbox Code Playgroud)

我得到许多不是英文的英文字符:例子:

- Khoda be khanevadehashon sabr bede tahamol konan
- Akhey...
- Eshghi
- K
- :-)
- Ey khodaa
- ...
- @samaneaghazamani1990 vaaaaay khoda chejoori payam dadan?
- :(
- Elahiiiii
- May Allah please with …
Run Code Online (Sandbox Code Playgroud)

php python text nlp language-detection

-5
推荐指数
1
解决办法
817
查看次数