我正在开发一个用户能够以特殊格式输入事实和规则的项目,但是我在检查该格式是否正确并获取信息方面遇到了一些麻烦.
当程序启动时,用户可以在文本区域中输入"命令",并将该文本发送到一个parseCommand方法,该方法根据用户编写的内容确定要执行的操作.例如,要添加事实或规则,您可以使用前缀+.或用于-删除事实或规则等.
我创建了处理前缀的系统,但我遇到了事实和规则格式的问题.
事实:这些由字母数字名称定义,并包含属性列表(每个属性都带有<>符号)和真值.属性也由字母数字名称定义,并包含2个字符串(称为参数),每个字符串都带有<>符号.通过!在列表中放置一个属性也可以为负.例如,用户可以键入以下内容将这3个事实添加到程序中:
+father(<parent(<John>,<Jake>)>, true)
+father(<parent(<Jammie>,<Jake>)>, false)
+father(!<parent(<Jammie>,<Jake>)>, true)
+familyTree(<parent(<John>,<Jake>)>, <parent(<Jammie>,<Jake>)> , true)
+fathers(<parent(<John>,<Jake>)>, !<parent(<Jammie>,<Jake>)> , true)
Run Code Online (Sandbox Code Playgroud)
我用来存储事实的类是这样的:
public class Fact implements Serializable{
private boolean truth;
private ArrayList<Property> properties;
private String name;
public Fact(boolean truth, ArrayList<Property> properties, String name){
this.truth = truth;
this.properties = properties;
this.name = name;
}
//getters and setters here...
}
Run Code Online (Sandbox Code Playgroud)
规则:这些是2个属性之间的链接,它们由=>符号标识.再次,它们的名称是字母数字.属性是有限的,因为它们只能包含由大写字母组成的参数,第二个属性的参数必须与第一个属性的参数相同.规则还有2个其他参数,可以通过输入名称来设置或不设置(这些参数中的每一个都对应于规则的属性,可以是Negative或Reversive).例如:
+son(<parent(<X>,<Y>)> => …Run Code Online (Sandbox Code Playgroud) 我在运行MinGW一段时间后已经安装了Cygwin.但是当我尝试编译控制台时给了我:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/cc1.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
我已经制作了一个django表单,我想在其中传递一些我需要显示的上下文(主要是标签中的数据库条目,以便用户可以从中进行选择).因此我在get_context_data function这里添加上下文到现有的上下文,如下所示:
def get_context_data(self, **kwargs):
context = super(UploadView, self).get_context_data(**kwargs)
context['categories'] = Category.objects.all()
context['form'] = VideoForm
return context
Run Code Online (Sandbox Code Playgroud)
但是,表单不保存传递给数据库的信息.为什么那不起作用?
这是我的代码的一部分!
forms.py:
class VideoForm(forms.ModelForm):
category = forms.ModelChoiceField(queryset=Category.objects.all(), empty_label=None)
class Meta:
model = Video
fields = [
'title',
'description',
'description_short',
'category',
'time',
'thumbnail',
'type',
]
def clean_thumbnail(self):
picture = self.cleaned_data.get("thumbnail")
if not picture:
raise forms.ValidationError("No Image")
else:
w, h = get_image_dimensions(picture)
if w/h != (16/9):
raise forms.ValidationError("Image in wrong aspect ratio (should be 16:9)")
return picture
Run Code Online (Sandbox Code Playgroud)
upload.html(它很长,所以最好将它上传到Pastebin)
views.py:
class UploadView(LoginRequiredMixin, …Run Code Online (Sandbox Code Playgroud) 我正在开发一个视频网络播放器,我一直在Chrome (Version 63.0.3239.108 (Official Build) (64-bit))和Firefox上测试它(52.5.2 (64-bit)).在Chrome中,只要我移动滑块以便通过视频进行搜索,它就会跳回当前的视频播放时间,而不是用户想要播放视频的时间.
以下是处理此部分的函数:
function vidSeek(){
var seekto = vid.duration * (seekbar.value / 100);
vid.currentTime = seekto;
}
Run Code Online (Sandbox Code Playgroud)
这在Firefox中正如预期的那样工作(但是在firefox中有一个问题,似乎是默认样式覆盖了我正在写的那个,但我认为它与它无关)
这是包含滑块的控制栏的html:
<div id="playercontrolls">
<button id="playpausebtn">Pause</button>
<input id="seekslider" type="range" min="0" max="100" value="0" step="1"> <!-- Seek bar doesn't work-->
<span id="curtimetext" class="white-text"></span> / <span id="durtimetext" class="white-text"></span>
<button id="mutebtn">Mute</button>
<input id="volumeslider" type="range" min="0" max="100" value="100" step="1"> <!-- Volume bar works-->
<button id="fullscreenbtn">[]</button>
</div>
Run Code Online (Sandbox Code Playgroud)
我还制作了一个音量滑块,似乎在Firefox和Chrome中都有效(除了Firefox中的格斗问题)
代码是:
function setvolume(){
if(vid.muted && volumeslider.value != 0){
vid.muted = false;
mutebtn.innerHTML = …Run Code Online (Sandbox Code Playgroud) 我已经制作了标题和来源,但我不知道如何将它们联系起来.我在网上查了一下,但提供的命令不起作用(或者我不会在这里:)).
编译它(如果你使用GCC):
标题:
$ gcc -c whatever.h -o whatever.o
Run Code Online (Sandbox Code Playgroud)
资源:
$ gcc -c sample.c -o sample.o
Run Code Online (Sandbox Code Playgroud)
要链接文件以创建可执行文件:
$ gcc sample.o whatever.o -o sample
Run Code Online (Sandbox Code Playgroud)
我做错了什么.我正在使用geany进行写入(编译错误在这里),但命令在同一目录中的终端上执行.任何人都可以给我geany的构建命令,所以每当我想要包含一个头我可以编译和运行?
我有一个简单的C程序,表示控制台内的加载屏幕,但无法隐藏光标。我尝试提高睡眠功能的速度,以便重置游标计时器并且游标消失,但这不起作用。
有关如何隐藏光标的任何提示。
码:
#include <stdio.h>
#include <stdlib.h>
const int TIME = 1;
int main(int argc,char *argv[]){
int i;
while (1){
printf("loading");
for (i=0;i<3;i++){
sleep(TIME);
printf(".");
}
sleep(TIME);
printf("\r");
system("Cls");
sleep(TIME);
}
}
Run Code Online (Sandbox Code Playgroud) 问题
我正在开发一个 django 项目,其中我需要在多个应用程序上共享相同的数据库模型,例如,当用户打开页面时,页面会根据用户设置显示,用户可以在不同的应用程序中更改这些设置比显示页面的那个
此刻,我所做的浏览应用程序包含我的模型的最多(因为它是我开始的那个)和我有其他的应用程序,如watch_file和user_settings,然后导入
这是有效的,但我注意到我遇到了组织问题,我从一个文件跳到另一个文件以检查模型并且我正在到处导入......
我的潜在解决方案
我正在考虑在某处制作一个大模型文件,然后在它自己的模型文件中导入我需要的每个应用程序的模型,但是,我读到了这个问题,其中有人在评论中表示通常不会这样做
我还红色这个问题,它说在应用程序之间共享模型在组织方面根本不是一个好主意
问题
关于为我的项目正在使用的所有模型制作通用模型文件不是一个好主意,我将如何组织它以便我不必从不同的文件中导入这么多模型以使应用程序工作?
我可以创建一个类似帮助应用程序的东西,它不显示但仅用于通过将所有模型都放在models.py文件中并从此处导入其他应用程序来帮助其他应用程序吗?
我正在一个需要解析Ajax响应的站点上,看起来像这样:
{"comments": "[{\"model\": \"modelhandler.comment\", \"pk\": 4, \"fields\": {\"user\": 2, \"description\": \"hello this is a comment but I don't know if it's working yet.......\", \"replyto\": null, \"uploaded\": \"2018-01-10T20:35:40.856Z\", \"updated\": \"2018-01-10T20:35:40.856Z\"}}]"}
Run Code Online (Sandbox Code Playgroud)
我尝试从这个响应中获取数据,如下所示:
success: function (data) {
var json = JSON.parse(JSON.stringify(data));
$.each(json, function(key,value) {
alert(value.comments);
});
}
Run Code Online (Sandbox Code Playgroud)
然而,这提醒了我 undefined
这里注释字段中有1个注释但我可能有超过1.如何从这样的Json响应中检索数据?
编辑:
我记录了data对象,我得到了这个:
Object
comments
:
"[{"model": "modelhandler.comment", "pk": 4, "fields": {"user": 2, "description": "hello this is a comment but I din't know if it's working yet.......", "replyto": null, "uploaded": "2018-01-10T20:35:40.856Z", "updated": …Run Code Online (Sandbox Code Playgroud) 我有一个函数,两个字符串string_one和string_two一个指向字符的指针.
我想到了一种将它们添加到一起的方法:
while (*string_one){
string_one++;
}
*string_one = *string_two;
Run Code Online (Sandbox Code Playgroud)
但我看不到输出中的第二个字符串!
如何添加两个字符串呢?我接近了吗?