我想使用一个短前缀在rdflib中指定一个名称空间,但是遇到了麻烦。我认为答案必须非常简单。这是有问题的代码:
g = rdflib.parse("some_rdf.rdf")
rdf=rdflib.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
print "Name Spaces:"
for ns in g.namespaces():
print ns
print "Matching Triples"
print "length of type full uri",len([i for i in g.triples((None,rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),None))])
print "length of type truncated uri",len([i for i in g.triples((None,rdflib.term.URIRef('rdf:type'),None))])
print "length of type , using namespace",len([i for i in g.triples((None,rdf.type,None))])
Run Code Online (Sandbox Code Playgroud)
输出为:
Name Spaces:
('xml', rdflib.term.URIRef('http://www.w3.org/XML/1998/namespace'))
(u'foaf', rdflib.term.URIRef('http://xmlns.com/foaf/0.1/'))
(u'z', rdflib.term.URIRef('http://www.zotero.org/namespaces/export#'))
('rdfs', rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#'))
(u'bib', rdflib.term.URIRef('http://purl.org/net/biblio#'))
(u'dc', rdflib.term.URIRef('http://purl.org/dc/elements/1.1/'))
(u'prism', rdflib.term.URIRef('http://prismstandard.org/namespaces/1.2/basic/'))
('rdf', rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#'))
(u'dcterms', rdflib.term.URIRef('http://purl.org/dc/terms/'))
Matching Triples
length of type full uri 132
length of type …Run Code Online (Sandbox Code Playgroud) 例如,如果我这样使用std::find_if:
std::vector<Rect>::iterator it =
std::find_if(regions.begin(), regions.end(), find_region(x,y));
Run Code Online (Sandbox Code Playgroud)
我能it以一种简单的方式获得迭代器的索引吗?
我需要调整我的代码,以便它会在数字后修剪网址.例如,我希望删除List = 36后的所有内容.字母和特殊字符是唯一可以跟随列表编号的潜在字符.所以我只想在列表编号后面读取字母或特殊字符时修剪网址.谢谢.
提交时捕获的当前URL的示例
https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?List=36caab7e%2D2234%2D4981%2D8225%%2Easpx
https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?List=36,http://portal.test/testabc/Lists/TEST/AllItems.aspx
Run Code Online (Sandbox Code Playgroud)
我希望在提交时捕获的网址:
https://portal.test.com/sites/test/testabc/Lists/RFC/DispFormSort.aspx?List=36
我当前捕获url的方法的代码:
public static string GenerateShortUrl(SPList list, int itemId)
{
try
{
var item = list.GetItemById(itemId);
var itemUrl = string.Empty;
if (item.File == null)
itemUrl = SPContext.Current.Web.Url + "/" + list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?ID=" + item.ID;
else
itemUrl = SPContext.Current.Web.Url + "/" + item.Url;
var generatedShortedUrl = GetShortUrl(itemUrl);
return generatedShortedUrl;
}
catch (Exception ex)
{
Utilities.WriteError(ex.ToString());
throw new SPException("An error occurred while attempting to shorten a URL.", ex);
}
}
Run Code Online (Sandbox Code Playgroud)
private static string GetShortUrl(string …Run Code Online (Sandbox Code Playgroud) Eclipse Helios 3.6
Windows XP SP3
我通过以下方式使用Eclipse来下载guava SDK:
1)在Eclipse中,转到帮助>安装新软件...
2)在" 使用: "文本框中,我使用了以下URL
http://svn.codespot.com/a/eclipselabs.org/guava-bundle/trunk/repository/
3)它找到了Guava:用于Java 1.5运行时和SDK的谷歌核心库,所以我点击了每个消息的确定,然后他们似乎安装得很好.
现在我想在我的代码中使用它(对于Android应用程序)我试图将导入添加到我的一个类文件中
import com.google.common.collect.MapMaker;
Run Code Online (Sandbox Code Playgroud)
我收到编译错误消息
导入的com.google无法解析
为了将库添加到我的项目中,是否需要执行任何特殊步骤?
我一直在查看项目属性,我有一种感觉,我需要在Java Build Path> Libraries中添加一个条目,但我不知道要添加什么.
锯齿状数组和多维数组之间有什么区别.彼此之间有什么好处?
为什么Visual Studio不允许我这样做
MyClass[][] abc = new MyClass[10][20];
Run Code Online (Sandbox Code Playgroud)
(我们曾经在C++中这样做,但在C#中它用红色蠕动线强调[20] ..说无效的等级说明符)
但很高兴
MyClass[,] abc = new MyClass[10,20];
Run Code Online (Sandbox Code Playgroud)最后,我如何在一行中初始化它(就像我们在简单数组中一样{new xxx...}{new xxx....})
MyClass[][,][,] itemscollection;
Run Code Online (Sandbox Code Playgroud)我正在设计要在禁止使用动态内存的嵌入式环境中运行的软件。Lex和Yacc非常适合该应用程序。
我可以配置Lex和Yacc完全不使用动态内存分配吗?
是否可以将Lex和Yacc配置为使用预定义的内存块,并将动态内存使用限制为该预定义的空间?
是否可以将动态内存的使用限制为仅对程序进行初始化(即程序首次运行时)?
编辑: 作为对TonyK的响应,我希望解析器不使用动态内存。
谢谢
尝试编译以下C++代码片段时(完整源代码如下)
A::A(istream& i) {
vector<string> words( istream_iterator<int>(i), istream_iterator<int> );
words.begin();
}
Run Code Online (Sandbox Code Playgroud)
我收到了错误
istream_it.cpp:12: error: request for member ‘begin’ in ‘words’, which is of non-class type
‘std::vector<int, std::allocator<int> >(
std::istream_iterator<int, char, std::char_traits<char>, long int>,
std::istream_iterator<int, char, std::char_traits<char>, long int>)’
Run Code Online (Sandbox Code Playgroud)
我知道这个错误通常是由使用no-parameters运算符意外声明一个函数引起的,如
string s(); s.size();
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我已经删除了所有不必要的代码,仍然无法确定究竟出现了什么问题,或者正确的语法是什么.
完整来源:
#include <sstream>
#include <vector>
#include <iterator>
#include <string>
using namespace std;
class A {
public:
A(istream& i) {
vector<int> words(istream_iterator<int>(i), istream_iterator<int> );
words.begin();
}
};
int main(int argc, char** argv)
{
istringstream iss("1 2 3");
A …Run Code Online (Sandbox Code Playgroud) 我刚刚完成了一个iPhone应用程序编程课程.作为课程的一部分,我看到了
@try指令提供异常处理return nil我问我是否应该对我编写的新代码使用异常处理(例如,如果我同时编写前端和逻辑代码,那么它们之间的通信就在我手中)但是我被告知不,我不应该使用新的异常码.(但他没有详细说明,然后课程继续进行,我想也许后来原因会变得清晰......)
当然例外优于return nil?你可以捕获特定的类型,你不要忽略通常成功的函数的返回类型来忽略它们,你有可以记录的文本消息,它们允许你的代码专注于正常情况,因此更具可读性.为什么要使用例外.
所以你怎么看?我的教练是不是不使用Objective-C例外?如果是这样,为什么?
我试图使用以下代码进行分页,但没有运气:
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'cat' => '5',
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $page,
);
query_posts($args);
while(have_posts()) {
the_post(); ?>
<div class="project_item">
<div class="dotted">
<hr />
</div>
<div class="project_thumb"><a href="<?php echo get_permalink(); ?>"><img src="<?php getCustomField('news_thumbnail'); ?>" /></a></div>
<div class="project_entry"><h4><a href="<?php echo get_permalink(); ?>"><?php getCustomField('news_title'); ?></a></h4>
<?php getCustomField('news_excerpt'); ?>
<a href="<?php echo get_permalink(); ?>" class="readmore">Read more..</a>
</div>
</div>
<?php }
wp_reset_query(); // Restore global post data
Run Code Online (Sandbox Code Playgroud) 我最近继承了一些Web代码,发现所有Java Script脚本都包含在HTML注释标记中
例如:
<script type="text/javascript" language="javascript"><!--
function ValidateForm() { ... }//-->
Run Code Online (Sandbox Code Playgroud)
据我了解,这种方法可以防止较旧的,不受支持的浏览器解释您的Java脚本.然而,这不是我曾经教过的事情,我想知道现在这被认为是不必要的,还是这仍然是一种常见的做法?如果是这样,为什么?
更新:感谢kennebec建议你留下他们,我现在已经做了,感谢Emmett:我一定会把它们留在我编写的任何未来代码中!